杭电1260

DP,数组分部模拟就好啦,别再忘啦!!!

#include 
#include 
#include 
using namespace std;
#define inf 1<<29
int N,K;
int TimeNeed[2100];
int TimeNeigh[2100];
int Min;
int main()
{
	int i,j;
	int h,m,s;
	scanf("%d",&N);
	while(N--)
	{
		 Min=inf;
		 memset(TimeNeed,0,sizeof(TimeNeed));
		 memset(TimeNeigh,0,sizeof(TimeNeigh));
		scanf("%d",&K);
		for(i=1;i<=K;i++)
		scanf("%d",&TimeNeed[i]);
		for(i=1;i<=K-1;i++)
		scanf("%d",&TimeNeigh[i]);
		for(i=2;i<=K;i++)		//DP核心思想呀,分部保存,别再忘啦,数组模拟 
		{
			TimeNeed[i]=min(TimeNeed[i-1]+TimeNeed[i],TimeNeed[i-2]+TimeNeigh[i-1]);
		}
		Min=TimeNeed[K];
		h=8;
		m=s=0;
		h+=Min/3600;
		m+=Min%3600/60;
		s+=Min%3600%60;
		h%=24;
		m%=60;
		s%=60;
		if(h<12)printf("%02d:%02d:%02d am\n",h,m,s);
		else
		printf("%02d:%02d:%02d pm\n",h,m,s);
	}
return 0;
}


你可能感兴趣的:(动态规划)