#include<bits/stdc++.h> #define ALL(X) X.begin(),X.end() #define FOR(I,A,B) for(int I = A; I <= B; I++) #define FORW(I,A,B) for(int I = A; I < B; I++) #define FORD(I,A,B) for(int I = A; I >= B; I--) #define CLEAR(X) memset(X,0,sizeof(X)) #define SIZE(X) int(X.size()) #define CONTAINS(A,X) (A.find(X) != A.end()) #define PB push_back #define MP make_pair #define X first #define Y second using namespace std; typedef signed long long slong; typedef long double ldouble; const slong INF = 1000000100; const ldouble EPS = 1e-9; const int MAXN = 2020; int DP[MAXN][MAXN]; int A[MAXN][MAXN]; int main() { while (true) { int N, K; if (scanf("%d %d", &N, &K) != 2) return 0; FOR(i,1,N) FOR(j,1,i) scanf("%d", &A[i][j]); FOR(i,1,N) FOR(j,1,i) DP[i][j] = 1 + DP[i-1][j-1] + DP[i-1][j] - DP[i-2][j-1]; // FOR(i,1,5) { FOR(j,1,i) cout << DP[i][j] << " "; cout << endl; } int result = INF; FOR(i,1,N) FOR(j,1,i) if(DP[i][j] <= K) result = min(result, A[i][j]); printf("%d\n", result); } }
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 | #include<bits/stdc++.h> #define ALL(X) X.begin(),X.end() #define FOR(I,A,B) for(int I = A; I <= B; I++) #define FORW(I,A,B) for(int I = A; I < B; I++) #define FORD(I,A,B) for(int I = A; I >= B; I--) #define CLEAR(X) memset(X,0,sizeof(X)) #define SIZE(X) int(X.size()) #define CONTAINS(A,X) (A.find(X) != A.end()) #define PB push_back #define MP make_pair #define X first #define Y second using namespace std; typedef signed long long slong; typedef long double ldouble; const slong INF = 1000000100; const ldouble EPS = 1e-9; const int MAXN = 2020; int DP[MAXN][MAXN]; int A[MAXN][MAXN]; int main() { while (true) { int N, K; if (scanf("%d %d", &N, &K) != 2) return 0; FOR(i,1,N) FOR(j,1,i) scanf("%d", &A[i][j]); FOR(i,1,N) FOR(j,1,i) DP[i][j] = 1 + DP[i-1][j-1] + DP[i-1][j] - DP[i-2][j-1]; // FOR(i,1,5) { FOR(j,1,i) cout << DP[i][j] << " "; cout << endl; } int result = INF; FOR(i,1,N) FOR(j,1,i) if(DP[i][j] <= K) result = min(result, A[i][j]); printf("%d\n", result); } } |