#include <cstdio> const int MAXN = 2001; int UP[MAXN][MAXN]; int main() { int best = 2020; int n, k; scanf("%d%d", &n, &k); int size = n*(n+1)/2; UP[0][0] = 1; UP[1][0] = 2; UP[1][1] = 2; for (int i=2; i<n; ++i) { for (int j=1;j<i;++j) UP[i][j] = UP[i-1][j-1] + UP[i-1][j] - UP[i-2][j-1] + 1; UP[i][0] = i+1; UP[i][i] = i+1; } // for (int i=0; i<2000; ++i) { // for (int j=0; j<=i; ++j) { // printf("%5d ", UP[i][j]); // } // printf("\n"); // } int row = 0; int pos = 0; int rowLen = 1; for (int i=0; i<=size; ++i) { int tmp; scanf("%d", &tmp); if (UP[row][pos] <= k && tmp < best) best = tmp; pos++; if (pos == rowLen) { row++; rowLen++; pos = 0; } } printf("%d\n", best); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <cstdio> const int MAXN = 2001; int UP[MAXN][MAXN]; int main() { int best = 2020; int n, k; scanf("%d%d", &n, &k); int size = n*(n+1)/2; UP[0][0] = 1; UP[1][0] = 2; UP[1][1] = 2; for (int i=2; i<n; ++i) { for (int j=1;j<i;++j) UP[i][j] = UP[i-1][j-1] + UP[i-1][j] - UP[i-2][j-1] + 1; UP[i][0] = i+1; UP[i][i] = i+1; } // for (int i=0; i<2000; ++i) { // for (int j=0; j<=i; ++j) { // printf("%5d ", UP[i][j]); // } // printf("\n"); // } int row = 0; int pos = 0; int rowLen = 1; for (int i=0; i<=size; ++i) { int tmp; scanf("%d", &tmp); if (UP[row][pos] <= k && tmp < best) best = tmp; pos++; if (pos == rowLen) { row++; rowLen++; pos = 0; } } printf("%d\n", best); return 0; } |