Tickets HDU - 1260 水DP

HDU - 1260

现在有n个人要买电影票,如果知道每个人单独买票花费的时间,

还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票。

直接dp就行,注意下输出和初始化

每次从dp[i-1]和dp[i-2]里面选一个就好

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(b,a) cout<<#a<<"["<<b<<"]="<<a[b]<<endl;
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
int dp[maxn];
int a[maxn],b[maxn];

int main(){
//#define test
#ifdef test
    freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
  cin>>casn;
  while(casn--){
	cin>>n;
	memset(dp,0,sizeof dp);
	rep(i,1,n) cin>>a[i];
	rep(i,2,n) cin>>b[i];
	dp[1]=a[1];
      rep(i,2,n) {
  	  dp[i]=min(dp[i-1]+a[i],dp[i-2]+b[i]);
      }
      int h=8+dp[n]/3600;
      int m=(dp[n]%3600)/60;
      int s=dp[n]%60;
	printf("%02d:%02d:%02d %s\n",h%12,m,s,h<12?"am":"pm");
  }
#ifdef test
    fclose(stdin);fclose(stdout);system("gedit ./out.txt");
#endif
    return 0;
}

dp