标签:search images char noi1999 ota har cli output mic
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 15581 | Accepted: 5534 |
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 <cstdlib> 4 #include <cstring> 5 #include <cmath> 6 #define min(a, b) ((a) < (b) ? (a) : (b)) 7 #define dist(x1, y1, x2, y2) (g[(x2)][(y2)] - g[((x1) - 1)][(y2)] - g[(x2)][((y1) - 1)] + g[((x1) - 1)][((y1) - 1)]) 8 9 inline void read(long long &x) 10 { 11 x = 0;char ch = getchar(), c = ch; 12 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 13 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 14 if(c == ‘-‘)x = -x; 15 } 16 17 const long long MAXN = 15 + 5; 18 19 long long n, g[10][10], dp[MAXN][10][10][10][10], sum; 20 21 int main() 22 { 23 read(n); 24 for(register long long i = 1;i <= 8;++ i) 25 for(register long long j = 1;j <= 8;++ j) 26 { 27 read(g[i][j]); 28 sum += g[i][j]; 29 g[i][j] = g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1] + g[i][j]; 30 } 31 memset(dp, 0x3f, sizeof(dp)); 32 //dp[i][x1][y1][x2][y2]表示把(x1,y1)(x2,y2)矩形切割成i块的最小平方和 33 for(register long long i = 1;i <= n;++ i) 34 for(register long long x1 = 1;x1 <= 8;++ x1) 35 for(register long long y1 = 1;y1 <= 8;++ y1) 36 for(register long long x2 = 1;x2 <= 8;++ x2) 37 for(register long long y2 = 1;y2 <= 8;++ y2) 38 { 39 if(i == 1) 40 { 41 dp[i][x1][y1][x2][y2] = dist(x1, y1, x2, y2)*dist(x1, y1, x2, y2); 42 continue; 43 } 44 for(register long long a = x1;a < x2;++ a) 45 { 46 dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - 1][x1][y1][a][y2] + dist(a + 1, y1, x2, y2)*dist(a + 1, y1, x2, y2)); 47 dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - 1][a + 1][y1][x2][y2] + dist(x1, y1, a, y2)*dist(x1, y1, a, y2)); 48 } 49 for(register long long a = y1;a < y2;++ a) 50 { 51 dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - 1][x1][y1][x2][a] + dist(x1, a + 1, x2, y2)*dist(x1, a + 1, x2, y2)); 52 dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - 1][x1][a + 1][x2][y2] + dist(x1, y1, x2, a)*dist(x1, y1, x2, a)); 53 } 54 } 55 printf("%.3lf", (double)sqrt(((double)dp[n][1][1][8][8]*1.0/n) - ((double)sum*1.0/n) * ((double)sum*1.0/n))); 56 return 0; 57 }
标签:search images char noi1999 ota har cli output mic
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7488955.html