用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. 微信小程序运行机制

    对于扫描接口B生成的带参小程序码的问题: (1)线上版本 扫描不同带参的小程序码会重新执行小程序的整个注册程序生命周期(详细生命周期函数见官方文档), (2)扫描相同的二维码的时候,目前微信官方给出的 ...

  2. centos6.5编译安装php7,及配置与nginx通信。

    一.配置编译环境 yum update && yum upgrade yum groupinstall "Development Tools" yum instal ...

  3. 安装完SAP后BASIS的配置流程

    安装完SAP后BASIS配置流程 安装完SAP后,配置流程. 1.升级kernel. 2.TCD SLICENSE: License Administration install > Syste ...

  4. RPC原理与实践(一)----RPC原理与实现(Thrift版)

    什么是RPC?为什么要使用RPC? 首先什么是RPC,RPC全称Remote Process Call,远程过程调用,现在几乎所有的公司都在使用RPC这种架构,诸如YOUTUBE使用的Thrift,B ...

  5. Hyperledger Fabric 替换couchDB

    fabric中默认数据存储的方式是levelDB,一个key/value存储的单机数据库.除此之外还提供了另外一种存储方式:couchDB.同样也是一个K/V 数据库,对fabric而言,相比于前者, ...

  6. JAVA接口详细讲解

    接口 接口的概念  接口代表的是一个功能的集合,定义规范,所有的方法都是抽像方法,这是一种思想是一种规则,将这个种规则称为接口. 接口的定义 使用关键字 interface 叫做接口 修饰符 inte ...

  7. 1366 - Incorrect string value:'\xE5\xBC\xA0\xE4\xB8\x89' for column 'name' a 错误修改

    把name的字符集修改成 utf8 ,然后把表关了从新打开,就可以了 如果还不行,就从新创表,在创表的时候修改name的字符集 如果还不行,就修改my.ini 它在你的mysql安装路径里 [mysq ...

  8. jQuery背景插件backstretch使用指南

    http://www.bkjia.com/Javascript/987917.html

  9. python 1 学习廖雪峰博客

    输出 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print('hello, world') p ...

  10. Mybatis 查询一个对象包含多个子对象 (List 包含 List)

    功能:查询一个数据列表 且每个数据中包含各自的子数据集合 使用场景:1. 当需要查询多订单数据且同时订单数据中需要包含订单明细数据时 2. 当需要查询多评论数据且同时评论数据中需要包含评论回复数据时 ...