codeforces 580D. Kefa and Dishes dp
来源:互联网 发布:mac telnet连接 编辑:程序博客网 时间:2024/06/17 03:03
题意
总共有
思路
n的数据范围比较小,可以用状压。S表示当前已经吃过的菜品的集合。题目中菜品吃的先后顺序是有关系的,所以还要记录S状态下最后一盘吃的菜品。
dp[s][i] 已经吃过的菜品的状态是S,并且最后一盘菜吃的是第i盘能得到的最大美味值。
枚举下一盘吃的菜j。一个状态
对应的有dp状态
答案便是吃了m给菜的所有
code
#include <bits/stdc++.h>using namespace std;int n, m, k;long long a[20];long long mc[20][20];long long dp[(1<<18)+5][20];int main () { scanf ("%d%d%d", &n, &m, &k); for (int i=0; i<n; i++) { scanf ("%I64d", &a[i]); } int tmp_x, tmp_y, tmp_c; for (int i=0; i<k; i++) { scanf ("%d%d%I64d", &tmp_x, &tmp_y, &tmp_c); mc[tmp_x-1][tmp_y-1] = tmp_c; } long long ans = 0; memset(dp, 0, sizeof(dp)); for (int i=0;i<n; i++) { dp[1<<i][i] = a[i]; } for (int s=0; s<(1<<n); s++) { int _cnt = 0; for (int i=0; i<n; i++) { if ((s & (1 << i)) == 0) continue; _cnt++; for (int j=0; j<n; j++) { if ((s & (1 << j)) != 0) continue; int _s = s | (1 << j); dp[_s][j] = max(dp[_s][j], dp[s][i] + a[j] + mc[i][j]); } } if (_cnt == m) for (int i=0; i<n; i++) if ((s & (1 << i)) != 0) ans = max(ans, dp[s][i]); } // for (int i=0; i<(1<<n); i++) { // for (int j=0; j<n; j++) { // printf("%d ", dp[i][j]); // }printf("\n"); // } printf ("%I64d\n", ans); return 0;}
0 0
- codeforces 580D. Kefa and Dishes dp
- codeforces 580 D.Kefa and Dishes(状压DP)
- codeforces 580 D. Kefa and Dishes (状压dp)
- codeforces 580D. Kefa and Dishes(状压dp)
- CodeForces 580D Kefa and Dishes(DP)
- codeforces 580D Kefa and Dishes【状态压缩+dp】
- Codeforces 580D Kefa and Dishes(dp+状态压缩)
- Codeforces 580D Kefa and Dishes【状压dp】
- codeforces 580D Kefa and Dishes (状压dp)
- CodeForces 580D.Kefa and Dishes(状压DP)
- CodeForces 580 D.Kefa and Dishes(状压DP)
- CodeForces 580D (状压DP) Kefa and Dishes
- Codeforces 580D Kefa and Dishes
- codeforces 580D Kefa and Dishes
- [codeforces 580D]Kefa and Dishes
- codeforces 580D. Kefa and Dishes
- Codeforces 580D Kefa and Dishes
- codeforces 321# D. Kefa and Dishes (状态压缩DP)
- ubuntu 安装jdk
- linux状态及原理全剖析
- oracle sql查询大全
- 反转链表
- 多功能采集模块——iPotest-PLV107
- codeforces 580D. Kefa and Dishes dp
- 1012. 数字分类 (20)
- 谷歌官方Gradle文档
- Git基本命令和GitFlow工作流
- 火云开发课堂 - 《Shader从入门到精通》系列 第十节:在Shader中实现模糊滤镜
- webview记录
- 设计模式笔记(十一)--建造者模式、原型模式、单例模式
- xshell 拖拽命令
- Bias Variance Tradeoff