【DP】 cf 321E
来源:互联网 发布:淘宝双11广告视频 编辑:程序博客网 时间:2024/05/17 01:35
用四边形优化一下dp即可。。。。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxm = 808;const int maxn = 4004;const int INF = 0x3f3f3f3f;int f[maxm][maxn];int s[maxm][maxn];int a[maxn][maxn];int n, m;void read(int &x){x = 0;char ch = getchar();while(ch == ' ' || ch == '\n') ch = getchar();while(ch != ' ' && ch != '\n') x = x * 10 + ch - '0', ch = getchar();}int calc(int i, int j){return a[j][j] - a[i-1][j] - a[j][i-1] + a[i-1][i-1];}void work(){scanf("%d%d", &n, &m);for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++) read(a[i][j]);for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++)a[i][j] += a[i][j-1];for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++)a[i][j] += a[i-1][j];memset(f, INF, sizeof f);f[0][0] = 0;for(int i = 1; i <= m; i++)for(int j = n; j >= 1; j--) {for(int k = s[i-1][j]; k <= (j == n ? n : s[i][j+1]) && k < j; k++) {if(f[i][j] > f[i-1][k] + calc(k+1, j)) {f[i][j] = f[i-1][k] + calc(k+1, j);s[i][j] = k;}}}printf("%d\n", f[m][n] / 2);}int main(){//freopen("data", "r", stdin);work();return 0;}
0 0
- 【DP】 cf 321E
- cf 459E DP
- CF 254E Dormitory(DP)
- CF-14E - Camels(DP)
- CF-31E-TV Game(dp)
- CF-51E - Pentagon(DP)
- CF 189DIV2 E DP + 斜率优化
- 【cf 570e】Pig and Palindromes dp
- 【CF 731E】Funny Game(DP)
- cf#302 E. Remembering Strings 状压dp
- cf-e
- CF 108E Garden(DP,斯坦纳树)
- CF 256E Lucky Arrays(线段树+DP)
- CF-18E - Flag 2(DP多阶段决策)
- CF 256E Lucky Arrarys 【线段树+DP】
- CF 416E - President's Path(floyd + DP)
- CF 479E Riding in a Lift 前缀和 DP
- cf #311 E. Ann and Half-Palindrome (dp+字典树)
- win7 mysql 免安装版 配置注册问题
- Homestead 集成开发环境配置
- 测试工具ab.exe 的使用
- TFS(一)--概述
- CLRS 16.2贪心算法的原理
- 【DP】 cf 321E
- CTP开发——资金转账(银期转账)
- 多线程之NSOperation
- Socket编程实践(7) --Select-I/O复用
- SPI总线协议及SPI时序图详解
- PhpExcel中文帮助手册|PhpExcel使用方法
- Map<K,V>根据值得到键
- 【DP】秘密文件
- RedHat5.7 yum更换为CentOS yum