std & random

Laffey 2022-03-26 18:59:06

std

#include <cstdio>
using namespace std;

const int MAXN = 1e3 + 10;
int f[MAXN][MAXN];
int a[MAXN][MAXN];

const int max(const int & a, const int & b) { return (a > b) ? a : b; }

int main()
{
//    freopen("num9.in", "r", stdin);
//    freopen("num9.ans", "w", stdout);
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    for (int i = 1; i <= x; i++) {
        for (int j = 1; j <= i; j++) {
            f[i][j] = max(f[i - 1][j], f[i - 1][j - 1]) + a[i][j];
        }
    }

    f[x][y - 1] = 0;
    for (int i = x + 1; i <= n; i++) {
        for (int j = y; j <= i; j++) {
            f[i][j] = max(f[i - 1][j], f[i - 1][j - 1]) + a[i][j];
        }
    }

    int ans = 0;
    for (int i = y; i <= n; i++) {
        ans = max(ans, f[n][i]);
    }
    printf("%d", ans);
    return 0;
}

random

#include <cstdio>
#include <cstdlib>
#include <ctime>
using namespace std;

const int MODS[10] = {10, 10, 10, 30, 30, 200, 200, 700, 700, 1000};
int c = 0;
const int random()
{
    return (rand() * rand()) % MODS[c];
}
const int ns[10] = {3, 7, 9, 13, 46, 102, 234, 456, 702, 1000};
const int xs[10] = {2, 5, 8, 12, 20, 13, 187, 333, 21, 523};
const int ys[10] = {1, 4, 8, 4, 6, 12, 108, 289, 12, 410};

int main()
{
    char o[8] = "num0.in";
    while (o[3] <= '9') {
    	srand(time(0));
        freopen(o, "w", stdout);
        int n = ns[c];
        int x = xs[c], y = ys[c];
        printf("%d %d %d\n", n, x, y);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                printf("%d ", random());
            }
            printf("\n");
        }
        if (o[3] == '0') {
        	o[3] = '1';
        }
        else
            o[3]++;
        c++;
    }
    return 0;
}

欢迎挑错