#include <bits/stdc++.h> #define FOR(i, a, b) for(int i = a; i<b; ++i) #define FR(i, a, b) for(int i = a; i>=b; --i) #define _upgrade cin.tie(0); ios_base::sync_with_stdio(0) #define pb push_back #define mp make_pair #define INF 1e9 using namespace std; typedef long long ll; typedef double db; typedef unsigned long long ull; typedef pair<int, int> iPair; const int MAX = 1e6 +1; const int MOD = 1e9 +7; int dp[2001][2001], tab[2001][2001]; int main() { _upgrade; int n, k, ans = INF; cin>>n>>k; FOR(i, 0, n) FOR(j, 0, i+1) cin>>tab[i][j]; FOR(i, 0, n) FOR(j, 0, i+1) { int a, b, c; if(j == i) a = 0; else a = dp[i-1][j]; if(j == 0) b = 0; else b = dp[i-1][j-1]; if(i <= 1 || j == 0) c = 0; else c = dp[i-2][j-1]; dp[i][j] = a + b - c + 1; if(dp[i][j] <= k) ans = min(ans, tab[i][j]); } cout<<ans<<"\n"; }
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 52 53 54 55 56 57 58 | #include <bits/stdc++.h> #define FOR(i, a, b) for(int i = a; i<b; ++i) #define FR(i, a, b) for(int i = a; i>=b; --i) #define _upgrade cin.tie(0); ios_base::sync_with_stdio(0) #define pb push_back #define mp make_pair #define INF 1e9 using namespace std; typedef long long ll; typedef double db; typedef unsigned long long ull; typedef pair<int, int> iPair; const int MAX = 1e6 +1; const int MOD = 1e9 +7; int dp[2001][2001], tab[2001][2001]; int main() { _upgrade; int n, k, ans = INF; cin>>n>>k; FOR(i, 0, n) FOR(j, 0, i+1) cin>>tab[i][j]; FOR(i, 0, n) FOR(j, 0, i+1) { int a, b, c; if(j == i) a = 0; else a = dp[i-1][j]; if(j == 0) b = 0; else b = dp[i-1][j-1]; if(i <= 1 || j == 0) c = 0; else c = dp[i-2][j-1]; dp[i][j] = a + b - c + 1; if(dp[i][j] <= k) ans = min(ans, tab[i][j]); } cout<<ans<<"\n"; } |