#include <iostream> #include <algorithm> int main() { int n, k; std::scanf("%d %d", &n, &k); int tab[2000]; tab[0] = 1; int min; std::scanf("%d", &min); int tmp; int addend; int back, tmpback; for(int i = 1; i < std::min(k, n); ++i){ std::scanf("%d", &tmp); back = tab[0]++; if(tmp < min){ min = tmp; } for(int j = 1; j < i; ++j) { std::scanf("%d", &tmp); addend = std::min(j+1, i-j+1); tmpback = tab[j]; tab[j] = std::max(tab[j], back) + addend; if(tab[j] <= k && min > tmp){ min = tmp; } back = tmpback; } std::scanf("%d", &tmp); tab[i] = tab[0]; if(tmp < min){ min = tmp; } // for(int j = 0; j <= i; j++) { // std::cout << tab[j] << " " ; // } // std::cout << std::endl; } std::printf("%d \n", min); 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 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <algorithm> int main() { int n, k; std::scanf("%d %d", &n, &k); int tab[2000]; tab[0] = 1; int min; std::scanf("%d", &min); int tmp; int addend; int back, tmpback; for(int i = 1; i < std::min(k, n); ++i){ std::scanf("%d", &tmp); back = tab[0]++; if(tmp < min){ min = tmp; } for(int j = 1; j < i; ++j) { std::scanf("%d", &tmp); addend = std::min(j+1, i-j+1); tmpback = tab[j]; tab[j] = std::max(tab[j], back) + addend; if(tab[j] <= k && min > tmp){ min = tmp; } back = tmpback; } std::scanf("%d", &tmp); tab[i] = tab[0]; if(tmp < min){ min = tmp; } // for(int j = 0; j <= i; j++) { // std::cout << tab[j] << " " ; // } // std::cout << std::endl; } std::printf("%d \n", min); return 0; } |