标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12698 | Accepted: 4503 |
Description
Input
Output
Sample Input
3 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 3
Sample Output
1.633
Source
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cstdlib> 6 #include<cmath> 7 using namespace std; 8 9 const int inf=0x3fffffff; 10 const int maxn=9; 11 12 int n; 13 int str[maxn][maxn]; 14 int dp[16][maxn][maxn][maxn][maxn]; 15 bool vis[16][maxn][maxn][maxn][maxn]; 16 int sum[maxn][maxn][maxn][maxn]; 17 void cal() 18 { 19 int ans=0; 20 memset(sum,0,sizeof(sum)); 21 for(int i1=0;i1<=8;i1++) 22 for(int j1=0;j1<=8;j1++) 23 for(int i2=i1;i2<=8;i2++) 24 for(int j2=j1;j2<=8;j2++) 25 { 26 ans=0; 27 for(int i=i1;i<=i2;i++) 28 for(int j=j1;j<=j2;j++) 29 { 30 31 ans+=str[i][j]; 32 } 33 sum[i1][j1][i2][j2]=ans*ans; 34 sum[i1][j2][i2][j1]=ans*ans; 35 sum[i2][j2][i1][j1]=ans*ans; 36 sum[i2][j1][i1][j2]=ans*ans; 37 } 38 } 39 int DP(int k,int x,int y,int xx,int yy) 40 { 41 if(dp[k][x][y][xx][yy]>=0) return dp[k][x][y][xx][yy]; 42 if(k==n-1)return sum[x][y][xx][yy]; 43 int ans=0; 44 dp[k][x][y][xx][yy]=1<<29; 45 for(int i=x;i<xx;i++) 46 { 47 ans=min(DP(k+1,x,y,i,yy)+sum[i+1][y][xx][yy],DP(k+1,i+1,y,xx,yy)+sum[x][y][i][yy]); 48 dp[k][x][y][xx][yy]=min(ans,dp[k][x][y][xx][yy]); 49 } 50 for(int i=y;i<yy;i++) 51 { 52 ans=min(DP(k+1,x,y,xx,i)+sum[x][i+1][xx][yy],DP(k+1,x,i+1,xx,yy)+sum[x][y][xx][i]); 53 dp[k][x][y][xx][yy]=min(ans,dp[k][x][y][xx][yy]); 54 } 55 return dp[k][x][y][xx][yy]; 56 } 57 int main() 58 { 59 //freopen("in.txt","r",stdin); 60 int tol; 61 scanf("%d",&n); 62 tol=0; 63 for(int i=0;i<8;i++) 64 for(int j=0;j<8;j++) 65 { 66 scanf("%d",&str[i][j]); 67 tol+=str[i][j]; 68 } 69 cal(); 70 memset(dp,-1,sizeof(dp)); 71 DP(0,0,0,7,7); 72 double res=sqrt(dp[0][0][0][7][7]*1.0/n-((tol*1.0)/n*(tol*1.0)/n)); 73 printf("%.3f\n",res); 74 // } 75 return 0; 76 }
标签:
原文地址:http://www.cnblogs.com/codeyuan/p/4278872.html