#include<bits/stdc++.h> using namespace std; const int inf=2100; int dp[inf][inf]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k,ans=inf; cin >>n >>k; for(int i=2;i<=n+1;i++){ for(int j=2;j<=i;j++){ dp[i][j]=dp[i-1][j-1]+dp[i-1][j]-dp[i-2][j-1]+1; int here; //cout <<dp[i][j] <<" "; cin >>here; if(dp[i][j]<=k){ ans=min(ans,here); } } //cout <<"\n"; } cout <<ans; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include<bits/stdc++.h> using namespace std; const int inf=2100; int dp[inf][inf]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k,ans=inf; cin >>n >>k; for(int i=2;i<=n+1;i++){ for(int j=2;j<=i;j++){ dp[i][j]=dp[i-1][j-1]+dp[i-1][j]-dp[i-2][j-1]+1; int here; //cout <<dp[i][j] <<" "; cin >>here; if(dp[i][j]<=k){ ans=min(ans,here); } } //cout <<"\n"; } cout <<ans; } |