#include <stdio.h> int dp[2003][2003]; int t[2003][2003]; int main() { int n,k; scanf("%d%d",&n,&k); for (int i=0;i<n;i++) for (int j=0;j<=i;j++) scanf("%d",&t[i][j]); dp[0][0]=1; int best = t[0][0]; for (int i =1;i<n;i++) { for (int j=0;j<=i;j++) { if(j== 0 || j==i) { dp[i][j] = dp[i-1][0] + 1; if(k>i && t[i][j] < best) best = t[i][j]; continue; } dp[i][j] = dp[i-1][j-1] +dp[i-1][j] - dp[i-2][j-1] + 1; if(t[i][j] < best && k >=dp[i][j]) best = t[i][j]; } } printf("%d\n", best); }
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 <stdio.h> int dp[2003][2003]; int t[2003][2003]; int main() { int n,k; scanf("%d%d",&n,&k); for (int i=0;i<n;i++) for (int j=0;j<=i;j++) scanf("%d",&t[i][j]); dp[0][0]=1; int best = t[0][0]; for (int i =1;i<n;i++) { for (int j=0;j<=i;j++) { if(j== 0 || j==i) { dp[i][j] = dp[i-1][0] + 1; if(k>i && t[i][j] < best) best = t[i][j]; continue; } dp[i][j] = dp[i-1][j-1] +dp[i-1][j] - dp[i-2][j-1] + 1; if(t[i][j] < best && k >=dp[i][j]) best = t[i][j]; } } printf("%d\n", best); } |