#include <bits/stdc++.h> #include <queue> #define INF 99999999 #define LL long long using namespace std; int tab[2010][2010]; int main(){ ios_base::sync_with_stdio(false); int n,k,x; cin >> n >> k; for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ cin >> x; tab[i][j]=x; } } int mini = tab[1][1]; tab[1][1]=1; for(int i=2;i<=n;i++){ for(int j=1;j<=i;j++){ int w = tab[i-1][j]+tab[i-1][j-1]-tab[i-2][j-1]+1; //cout << tab[i][j] << "\n"; if(w<=k && tab[i][j]<mini){ mini = tab[i][j]; } tab[i][j] = w; } } cout << mini; 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 | #include <bits/stdc++.h> #include <queue> #define INF 99999999 #define LL long long using namespace std; int tab[2010][2010]; int main(){ ios_base::sync_with_stdio(false); int n,k,x; cin >> n >> k; for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ cin >> x; tab[i][j]=x; } } int mini = tab[1][1]; tab[1][1]=1; for(int i=2;i<=n;i++){ for(int j=1;j<=i;j++){ int w = tab[i-1][j]+tab[i-1][j-1]-tab[i-2][j-1]+1; //cout << tab[i][j] << "\n"; if(w<=k && tab[i][j]<mini){ mini = tab[i][j]; } tab[i][j] = w; } } cout << mini; return 0; } |