标签:ring last space number nes getchar eve test memset
The first line contains a single integer T, the number of test cases. For each case, the first line is n (0 < n <= 100)
The next n line are n integer D1-Dn means the value of diaosi of boys (0 <= Di <= 100)
For each test case, output the least summary of unhappiness . Sample Input
2 5 1 2 3 4 5 5 5 4 3 2 2
Case #1: 20 Case #2: 24
区间dp····用f[i][j]表示我们在只考虑让i到j个人上场的情况下能获得的最小不高兴值···,然后我们考虑让第i个人在第几个上场··枚举i到j中的k,考虑让第i人再第k个人之后上场··那么第i个人就是第i-k+1个上场的··对答案贡献是(i-k)*num[i],另外k+1到j个人也会对答案有新的贡献,为(i-k+1)*sum[k+1——j]
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<ctime> #include<cctype> #include<string> #include<cstring> #include<algorithm> using namespace std; const int N=105; const int inf=0x3f3f3f3f; int num[N],sum[N],f[N][N],T,n; inline int R() { char c;int f=0; for(c=getchar();c<‘0‘||c>‘9‘;c=getchar()); for(;c<=‘9‘&&c>=‘0‘;c=getchar()) f=(f<<3)+(f<<1)+c-‘0‘; return f; } int main() { // freopen("a.in","r",stdin); T=R(); for(int t=1;t<=T;t++) { n=R(); memset(sum,0,sizeof(sum)); for(int i=1;i<=n;i++) num[i]=R(),sum[i]=sum[i-1]+num[i]; memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) f[i][j]=inf; for(int i=n-1;i>=1;i--) for(int j=i+1;j<=n;j++) for(int k=i;k<=j;k++) f[i][j]=min(f[i][j],f[i+1][k]+f[k+1][j]+(k-i+1)*(sum[j]-sum[k])+num[i]*(k-i)); printf("Case #%d: %d\n",t,f[1][n]); } return 0; }
刷题总结——you are the one(hdu4283)
标签:ring last space number nes getchar eve test memset
原文地址:http://www.cnblogs.com/AseanA/p/7703618.html