Tickets HDU - 1260
考察:线性dp
思路:
很容易看出状态转移方程,坑到本蒟蒻的是计算时间,总之请记下来....
这里的f[n]是秒数.
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 const int N = 2010; 5 int one[N],two[N],n,f[N]; 6 int main() 7 { 8 int T; 9 scanf("%d",&T); 10 while(T--) 11 { 12 bool late = 0; 13 scanf("%d",&n); 14 for(int i=1;i<=n;i++) scanf("%d",&one[i]); 15 for(int i=2;i<=n;i++) scanf("%d",&two[i]); 16 f[1] = one[1]; 17 for(int i=2;i<=n;i++) 18 f[i] = min(f[i-2]+two[i],f[i-1]+one[i]); 19 int h = f[n]/60/60; 20 int m =f[n]%3600/60,s = f[n]%60; 21 if(h+8>=12) late = 1; 22 printf("%02d:%02d:%02d ",h+8,m,s); 23 if(late) printf("pm\n"); 24 else printf("am\n"); 25 } 26 return 0; 27 }