TYVJ 1108 守望者的逃离 解题报告
DP,DP方程好复杂,不知道怎么说的好,代码里分解吧:
#include <stdio.h> #include <stdlib.h> #define max(a, b) ((a)>(b)?(a):(b)) int g[300001][2], f[300001]; int main(int argc, char **argv) { int i, min = -1; int m, s, t; scanf("%d%d%d", &m, &s, &t); g[0][0] = m; for(i = 1; i <= t; i++){ if(g[i - 1][0] >= 10){ g[i][0] = g[i - 1][0] - 10; g[i][1] = g[i - 1][1] + 60; }else{ g[i][0] = g[i - 1][0] + 4; g[i][1] = g[i - 1][1]; } f[i] = max(f[i - 1] + 17, g[i][1]); if(min == -1 && f[i] >= s){ min = i; } } if(min == -1){ printf("No\n%d\n", f[t]); }else{ printf("Yes\n%d\n", min); } return 0; }