hdu2517 区间动规

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #define inf 1000000000
 5 int hash[10][10][10][10][20];
 6 int s[10][10][10][10],fsum[10][10][10][10];
 7 int dp(int x1,int y1,int x2,int y2,int k)
 8 {
 9     int a,b,sum,temp;
10     if (k==1) hash[x1][y1][x2][y2][k]=fsum[x1][y1][x2][y2];
11     if (hash[x1][y1][x2][y2][k]!=0) return(hash[x1][y1][x2][y2][k]);
12     sum=inf;
13     for (a=x1;a<x2;a++)
14     {
15         temp=dp(x1,y1,a,y2,k-1);
16         if (temp!=-1&&temp+fsum[a+1][y1][x2][y2]<sum) sum=temp+fsum[a+1][y1][x2][y2];
17         temp=dp(a+1,y1,x2,y2,k-1);
18         if (temp!=-1&&temp+fsum[x1][y1][a][y2]<sum) sum=temp+fsum[x1][y1][a][y2];
19     }
20     for (b=y1;b<y2;b++)
21     {
22         temp=dp(x1,y1,x2,b,k-1);
23         if (temp!=-1&&temp+fsum[x1][b+1][x2][y2]<sum) sum=temp+fsum[x1][b+1][x2][y2];
24         temp=dp(x1,b+1,x2,y2,k-1);
25         if (temp!=-1&&temp+fsum[x1][y1][x2][b]<sum) sum=temp+fsum[x1][y1][x2][b];
26     }
27     if (sum==inf) hash[x1][y1][x2][y2][k]=-1;
28     else hash[x1][y1][x2][y2][k]=sum;
29     return(hash[x1][y1][x2][y2][k]);
30 }
31 int main()
32 {
33     int n,i,j,x1,y1,x2,y2,map[10][10];
34     double h,f;
35     while (~scanf("%d",&n))
36     {
37         h=0.0;
38         for (i=1;i<=8;i++)
39          for (j=1;j<=8;j++)
40          {
41              scanf("%d",&map[i][j]);
42              h+=map[i][j];
43          }
44         memset(hash,0,sizeof(hash));
45         memset(s,0,sizeof(s));
46         for (x1=1;x1<=8;x1++)
47          for (y1=1;y1<=8;y1++)
48           for (x2=x1;x2<=8;x2++)
49            for (y2=y1;y2<=8;y2++)
50            {
51                s[x1][y1][x2][y2]=s[x1][y1][x2-1][y2]+s[x1][y1][x2][y2-1]-s[x1][y1][x2-1][y2-1]+map[x2][y2];
52                fsum[x1][y1][x2][y2]=s[x1][y1][x2][y2]*s[x1][y1][x2][y2];
53            }
54         f=1.0*dp(1,1,8,8,n);
55         h=(h/n)*(h/n);
56         printf("%0.3lf\n",1.0*sqrt(f/n-h));
57     }
58 }

http://acm.hdu.edu.cn/showproblem.php?pid=2517

转载于:https://www.cnblogs.com/xiao-xin/articles/3848660.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值