Description

Luogu4046

BZOJ1820

Solution

暴力DP很好想,\(f[i][j][k][l]\)表示处理到第\(i\)个任务,三个人在\(i,j,k\)的方案数。显然一个人应该在这个任务的地方,我们就省去那一维,注意要保证钦定办这个任务的人那一维一定被省略

Code

#include <algorithm>
#include <cstdio>
#include <cstring> const int N = 210;
const int INF = 0x3f3f3f3f; int G[N][N];
int f[2][N][N], n, P[1010]; inline void upd(int &x, const int &y) {
if (y < x) x = y;
} int main() {
n = read();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) G[i][j] = read();
memset(f, 0x3f, sizeof f);
f[0][2][3] = 0;
P[0] = 1;
int nw = 0, pw = 1, x, m = 0;
while (scanf("%d", &x) != EOF) {
std::swap(nw, pw);
P[++m] = x;
memset(f[nw], 0x3f, sizeof f[nw]);
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
upd(f[nw][j][k], f[pw][j][k] + G[P[m - 1]][x]);
upd(f[nw][k][P[m - 1]], f[pw][j][k] + G[j][x]);
upd(f[nw][j][P[m - 1]], f[pw][j][k] + G[k][x]);
}
}
}
int ans = 0x3f3f3f3f;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
upd(ans, f[nw][i][j]);
}
}
printf("%d\n", ans);
return 0;
}

最新文章

  1. IP变化,SVN和数据库的修改
  2. 为SubSonic3.0的查询(SubSonic.Query.Select和存储过程)添加更多的执行功能
  3. PetaPoco 批量插入数据
  4. cacti监控windows服务器
  5. [bzoj4326][NOIP2015]运输计划
  6. Android应用签名
  7. javascript 对象和数组(花括号、方括号)
  8. BestCoder Round #2
  9. mha 自动failover 原创
  10. spoj 2
  11. getaccesstoken方法
  12. 动态创建一些常的html标签
  13. Coursera 机器学习笔记(七)
  14. 没事不要在for循环期间增减迭代序列的成员
  15. linux知识汇总
  16. 通过go-ethereum源码看如何管理项目
  17. FormData上传文件(不是所有的浏览器都支持)
  18. MySQL学习笔记-锁相关话题
  19. MVC 图片上传 带进度条(转)
  20. MySQL案例07:MySQL5.7并发复制隐式bug

热门文章

  1. 【Android开发艺术探索】四大组件的工作过程
  2. nuget打包上传
  3. Eclipse 如何添加 更换字体(转载)
  4. python中class的定义及使用
  5. JVM第二篇 类加载子系统
  6. W25Q64BV(FLASH)(SPI)中文手册
  7. [TJOI2007] 足彩投注
  8. 吴裕雄--天生自然 HADOOP大数据分布式处理:安装WinSCP
  9. WebGL_0003:正则表达式查找字符串
  10. P4072 [SDOI2016]征途