用spfa,和dp是一样的。转移只和最后一个吃的dish和吃了哪些有关。

把松弛改成变长。因为是DAG,所以一定没环。操作最多有84934656,514ms跑过,实际远远没这么多。

脑补过一下费用流,但是限制流量不能保证吃到m个菜

#include<bits/stdc++.h>
using namespace std; typedef pair<int,int> nd;
typedef long long ll;
#define fi first
#define se second
int n,m,a[];
int g[][];
const int maxs = <<;
ll d[maxs][];
bool vis[maxs][];
inline int bitcount(int s)
{
int ct = ;
while(s){
ct += s&;
s >>= ;
}
return ct;
} ll spfa()
{
queue<nd>q;
ll ans = ;
for(int i = ; i < n; i++){
q.push(nd(<<i,i));
d[<<i][i] = a[i];
vis[<<i][i] = true;
}
while(q.size()){
nd &u = q.front(); vis[u.fi][u.se] = false;
int bc = bitcount(u.fi);
if(bc == m) { ans = max(ans,d[u.fi][u.se]); q.pop(); continue; }
for(int i = ; i < n; i++){
if(&(u.fi>>i)) continue;
int ns = <<i|u.fi;
if(d[ns][i] < d[u.fi][u.se] + g[u.se][i] + a[i]){
d[ns][i] = d[u.fi][u.se] + g[u.se][i] + a[i];
if(!vis[ns][i]){
q.push(nd(ns,i)); vis[ns][i] = true;
}
}
}
q.pop();
}
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
int k;scanf("%d%d%d",&n,&m,&k);
for(int i = ; i < n; i++){
scanf("%d",a+i);
}
while(k--){
int x,y; scanf("%d%d",&x,&y);
scanf("%d",g[x-]+y-);
}
printf("%I64d",spfa());
return ;
}

最新文章

  1. [Python] python vs cplusplus
  2. MATLAB plot函数的一些参数
  3. string.Join和Reverse的简单使用示例
  4. photoSlider-html5原生js移动开发轮播图-相册滑动插件
  5. CloseHandle(),TerminateThread(),ExitThread()的区别
  6. tolower (Function)
  7. 基于 Aspose.Cells与XML导入excel 数据----操作类封装
  8. Linux查看监听端口的脚本测试
  9. 问题记录2019-03-06(todo)
  10. 动态规划——Burst Ballons
  11. Clustering[Spectral Clustering]
  12. SpringBoot定时任务说明
  13. 2019年度【计算机视觉&amp;机器学习&amp;人工智能】国际重要会议汇总
  14. 浏览器执行代码 是jsp 服务端执行的是&lt;%%&gt;
  15. 人生苦短:Python里的17个“超赞操作
  16. 后台返回路由的数组,然后根事先写好的路由比对如果相等就放到一个数组中https://www.cnblogs.com/zhengrunlin/p/8981017.html
  17. 16进制转ascii,转字符串
  18. html + css + jquery实现简单的进度条实例
  19. [转载]《Delphi 版 everything、光速搜索代码》 关于获取文件全路径 GetFullFileName 函数的优化
  20. IOS开发之自定义键盘

热门文章

  1. POJ - 1458 Common Subsequence DP最长公共子序列(LCS)
  2. imgAreaSelect插件
  3. Python实现二叉树的前序、中序、后序、层次遍历
  4. argparse 在深度学习中的应用
  5. JSPs only permit GET POST or HEAD的解决方案(REST风格)
  6. Django之缓存+序列化+信号+ORM性能优化+验证码
  7. 【手撸一个ORM】第五步、Expression(表达式目录树)转换为Where子句
  8. Net Core IIS Express In
  9. F. Clique in the Divisibility Graph DP
  10. Jenkins+Gitlab+Ansible自动化部署(二)