#include <bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned LL #define LD long double const int INF = 1e9 + 2137; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); LL n, k; cin>>n>>k; LL dp[n+1][n+1]; for(int i=0; i<=n; i++) { for(int j=0; j<=n; j++) { if(j<=i) dp[i][j] = INF; else dp[i][j] = 0; } } dp[0][0] = 0; for(int i=1; i<n; i++) { for(int j=0; j<=i; j++) { if(j==0) dp[i][j] = dp[i-1][j] + 1; else if(j==i) dp[i][j] = dp[i-1][i-1] + 1; else if(i==1) dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + 1; else dp[i][j] = dp[i-1][j-1] + dp[i-1][j] - dp[i-2][j-1] + 1; } } /*for(int i=0; i<n; i++) { for(int j=0; j<=i; j++) cout<<dp[i][j]<<" "; cout<<endl; }*/ LL t[n][n]; for(int i=0; i<n; i++) { for(int j=0; j<=i; j++) { cin>>t[i][j]; } } LL w = INF; for(int i=0; i<n; i++) { for(int j=0; j<=i; j++) { if(dp[i][j]<k) w = min(w, t[i][j]); } } cout<<w; }
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> using namespace std; #define LL long long #define ULL unsigned LL #define LD long double const int INF = 1e9 + 2137; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); LL n, k; cin>>n>>k; LL dp[n+1][n+1]; for(int i=0; i<=n; i++) { for(int j=0; j<=n; j++) { if(j<=i) dp[i][j] = INF; else dp[i][j] = 0; } } dp[0][0] = 0; for(int i=1; i<n; i++) { for(int j=0; j<=i; j++) { if(j==0) dp[i][j] = dp[i-1][j] + 1; else if(j==i) dp[i][j] = dp[i-1][i-1] + 1; else if(i==1) dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + 1; else dp[i][j] = dp[i-1][j-1] + dp[i-1][j] - dp[i-2][j-1] + 1; } } /*for(int i=0; i<n; i++) { for(int j=0; j<=i; j++) cout<<dp[i][j]<<" "; cout<<endl; }*/ LL t[n][n]; for(int i=0; i<n; i++) { for(int j=0; j<=i; j++) { cin>>t[i][j]; } } LL w = INF; for(int i=0; i<n; i++) { for(int j=0; j<=i; j++) { if(dp[i][j]<k) w = min(w, t[i][j]); } } cout<<w; } |