标签:nbsp ref single algo div with std print set
Time Limit: 5000MS | Memory Limit: 512000KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
2 3 3 5 7 8 2 0 10 1 3 5 7 9 2 4 6 8 10 9 4 1 2 1 2 1 4 5 1
Sample Output
Case #1: 17 Case #2: 74
Hint
Source
1 /*by SilverN*/ 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 using namespace std; 8 const int mxn=240; 9 int read(){ 10 int x=0,f=1;char ch=getchar(); 11 while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 12 while(ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 13 return x*f; 14 } 15 int T; 16 int n; 17 int a[mxn],b[mxn]; 18 int f[mxn][mxn]; 19 int main(){ 20 T=read(); 21 int i,j; 22 int cas=0; 23 while(T--){ 24 // memset(f,0x3f,sizeof f); 25 memset(f,0,sizeof f); 26 n=read(); 27 for(i=1;i<=n;i++){a[i]=read();} 28 for(i=1;i<=n;i++){b[i]=read();} 29 a[n+1]=b[n+1]=0; 30 for(i=1;i<=n;i++) 31 for(j=i;j<=n;j++) 32 if(i==j)f[i][i]=a[i]+b[i-1]+b[i+1]; 33 else f[i][j]=0x3f3f3f3f; 34 for(int st=1;st<=n;st++) 35 for(i=1;i<=n-st;i++){ 36 j=i+st; 37 for(int k=i;k<=j;k++){ 38 f[i][j]=min(f[i][j],f[i][k-1]+f[k+1][j]+a[k]+b[i-1]+b[j+1]); 39 } 40 // printf("%d %d %d\n",i,j,f[i][j]); 41 } 42 43 printf("Case #%d: %d\n",++cas,f[1][n]); 44 } 45 return 0; 46 }
标签:nbsp ref single algo div with std print set
原文地址:http://www.cnblogs.com/SilverNebula/p/6022568.html