用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 ;
}

Codeforces Round #321 (Div. 2) D Kefa and Dishes(dp)的更多相关文章

  1. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

  2. Codeforces Round #267 (Div. 2) C. George and Job(DP)补题

    Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...

  3. Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp

    题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...

  4. Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)

    E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)

    dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点. #include<bits/stdc++.h> using namespace std; ; int ...

  6. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

  7. Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)

    http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...

  8. Codeforces Round #605 (Div. 3) D. Remove One Element(DP)

    链接: https://codeforces.com/contest/1272/problem/D 题意: You are given an array a consisting of n integ ...

  9. Codeforces Round #651 (Div. 2) E. Binary Subsequence Rotation(dp)

    题目链接:https://codeforces.com/contest/1370/problem/E 题意 给出两个长为 $n$ 的 $01$ 串 $s$ 和 $t$,每次可以选择 $s$ 的一些下标 ...

随机推荐

  1. NFS原理详解

    NFS原理详解 摘自:http://atong.blog.51cto.com/2393905/1343950 2013-12-23 12:17:31 标签:linux NFS nfs原理详解 nfs搭 ...

  2. Image Processing - Pseudo(False) Color Processing

    最近在一个项目中有需要用到将图片从GrayScale转为FalseColor,然而百度了一下Halcon 伪彩色等关键字均找不到相关答案,倒是有很多OpenCV和Matlab的...后来在搜索中看到了 ...

  3. 反射学习:(System.Reflection)

    反射为了动态(运行时动态) 原理:读取metadata(?)   Assembly assembly = Assembly.Load("TestReflections");//反射 ...

  4. VS~通过IIS网站启用"域名"调试

    在我们开发网站时,对某些信息进行序列化时,通常使用session,cookies,nosql等技术,而为了安全,我们在服务器上很多情况都做了防止盗链的设计,这给本机调试带来了不便,因为,本机都是以lo ...

  5. 使用ffmpeg编码时,如何设置恒定码率,并控制好关键帧I帧间隔

    1. 大家在使用ffmpeg进行视频编码时,使用-b命令,想控制比特率,却发现结果并没有如我们设置所愿,通过码流分析器观察视频码流,码率的波动还是很大的,ffmpeg控制的并不好,这时候,我们可以通过 ...

  6. selenium IDE界面介绍(转)

    1.文件:创建.打开和保存测试案例和测试案例集.编辑:复制.粘贴.删除.撤销和选择测试案例中的所有命令.Options : 用于设置seleniunm IDE. 2.用来填写被测网站的地址. 3.速度 ...

  7. Glassfish 设置时区

    对于Glassfish domain 或者instance下,某个日志的时区不对,前提是系统时区争取. 可以尝试通过如下命令查看jvm 时区设置 asadmin list-jvm-options 如果 ...

  8. [干货分享] AXURE-整套高保真UI框架和元件组(暗黑风格)

      写在前面 在我们的开发团队里,一般在产品通过策划和需求评审后,在还没开始设计之前,产品经理和美工会一起定一套UI规范. 一方面用于规范整体界面,防止界面开发过程中出现UI不一致性的情况(有时候标准 ...

  9. Java编码优化

    Java编码优化 1.尽可能使用局部变量 调用方法时传递的参数以及在调用中创建的临时变量都保存在栈中速度较快,其他变 量,如静态变量.实例变量等,都在堆中创建,速度较慢.另外,栈中创建的变量,随 着方 ...

  10. 使用一条sql语句查询多表的总数

    SELECT sum(列名1) 列名1,sum(列名2) 列名2,sum(列名3) 列名3 FROM ( SELECT count(*) 列名1, 列名2, 列名3 FROM 表1 -- WHERE ...