[CF580D]Kefa and Dishes
题意翻译
kefa进入了一家餐厅,这家餐厅中有n个菜(0<n<=18),kefa对第i个菜的满意度为ai(0<=ai<=10^9),并且对于这n个菜有k个规则,如果kefa在吃完第xi个菜之后吃了第yi个菜(保证xi、yi不相等),那么会额外获得ci(0<=ci<=10^9)的满意度。kefa要吃m道任意的菜(0<m<=n),但是他希望自己吃菜的顺序得到的满意度最大,请你帮帮kefa吧!
输入第一行是三个数:n,m,k
第二行是n个数,第i个数表示kefa对第i道菜的满意度为ai
第三行到第k+2行每行有3个数:xi,yi,ci,表示如果kefa在吃完第xi道菜之后立刻吃了第yi道菜,则会额外获得ci的满意度
Ps:这道题是个状压,因为n,m的范围都很小
简单的状压$dp$
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int n,m,p;ll ans;
ll a[],sum[<<],val[][],f[<<][];
int main() {
scanf("%d%d%d",&n,&m,&p);
for(int i=;i<n;i++) scanf("%lld",&a[i]);
for(int i=;i<=p;i++) {
int x,y,z;scanf("%d%d%d",&x,&y,&z);
x--,y--;val[x][y]=z;
}
for(int i=;i<(<<n);i++) sum[i]=sum[i>>]+(i&);
for(int i=;i<n;i++) f[<<i][i]=a[i];
for(int i=;i<(<<n);i++)
for(int j=;j<n;j++) {
if(((<<j)&i)==) continue;
for(int k=;k<n;k++) {
if(((<<k)&i)!=) continue;
f[i|(<<k)][k]=max(f[i|(<<k)][k],f[i][j]+val[j][k]+a[k]);
}
}
for(int i=;i<(<<n);i++)
for(int j=;j<n;j++)
if(sum[i]==m)
ans=max(ans,f[i][j]);
printf("%lld\n",ans);
return ;
}
[CF580D]Kefa and Dishes的更多相关文章
- CF580D Kefa and Dishes 状压dp
When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. Th ...
- CF580D Kefa and Dishes 【状压dp】By cellur925
题目传送门 友情链接:new2zydalao%%% 一篇优秀的状压文章 题目大意:$n$个菜有$k$个规则,如果kefa在吃完第$xi$个菜之后吃了第$yi$个菜(保证$xi$.$yi$不相等), ...
- CF580D Kefa and Dishes (状压DP)
枚举最后食物 #include <iostream> #include <cstdio> #include <cstring> #include <algor ...
- 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 ...
- dp + 状态压缩 - Codeforces 580D Kefa and Dishes
Kefa and Dishes Problem's Link Mean: 菜单上有n道菜,需要点m道.每道菜的美味值为ai. 有k个规则,每个规则:在吃完第xi道菜后接着吃yi可以多获得vi的美味值. ...
- codeforces 580D:Kefa and Dishes
Description When Kefa came to the restaurant and sat at a table, the waiter immediately brought him ...
- codeforces 580D. Kefa and Dishes
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 580D Kefa and Dishes(状压DP)
题目大概说要吃掉n个食物里m个,吃掉各个食物都会得到一定的满意度,有些食物如果在某些食物之后吃还会增加满意度,问怎么吃满意度最高. dp[S][i]表示已经吃掉的食物集合是S且刚吃的是第i个食物的最大 ...
- codeforces 580D Kefa and Dishes(状压dp)
题意:给定n个菜,每个菜都有一个价值,给定k个规则,每个规则描述吃菜的顺序:i j w,按照先吃i接着吃j,可以多增加w的价值.问如果吃m个菜,最大价值是多大.其中n<=18 思路:一看n这么小 ...
随机推荐
- 【CSS系列】图像映射
<!DOCTYPE html > <html xmlns="http://www.w3.org/1999/xhtml"> <head> < ...
- 键盘event.which属性
IE中,只有keyCode属性,而FireFox中有which和charCode属性 event.which属性对DOM原生的event.keyCode和event.charCode进行了标准化. f ...
- c# Use NAudio Library to Convert MP3 audio into WAV audio(将Mp3格式转换成Wav格式)
Have you been in need of converting mp3 audios to wav audios? If so, the skill in this article prov ...
- windows下resin的配置部署与调试
配置 从Resin官网(http://www.caucho.com)下载Resin解压后,启动Resin,运行resin根目录下的resin.exe文件,运行期间将出现下图所示的命令提示符窗口. 表示 ...
- 树链剖分-点的分治(点数为k且距离最长的点对)
hdu4871 Shortest-path tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 130712/130712 K ( ...
- wampserver3 集成环境 启动Apache失败
前提:安装完成后,原先是能够启动服务,但是按照网上教程修改conf文件后就不能启动Apache, 方法: 1.查看Apache错误日志(无奈的是看不懂) 2.在cmd命令行中查看,(打开cmd,输入: ...
- 170804、使用Joda-Time优雅的处理日期时间
简介 在Java中处理日期和时间是很常见的需求,基础的工具类就是我们熟悉的Date和Calendar,然而这些工具类的api使用并不是很方便和强大,于是就诞生了Joda-Time这个专门处理日期时间的 ...
- kubernetes实战(十):k8s使用Helm安装harbor
1.基本概念 对于复杂的应用中间件,需要设置镜像运行的需求.环境变量,并且需要定制存储.网络等设置,最后设计和编写Deployment.Configmap.Service及Ingress等相关yaml ...
- PAT 1044 Shopping in Mars[二分][难]
1044 Shopping in Mars(25 分) Shopping in Mars is quite a different experience. The Mars people pay by ...
- Java实现最基本的集中排序
排序是一个很重要的概念,现实生活中,我们需要为很多的东西排序.下面我们就介绍几种简单的排序的方法和最基本的思想. 1.冒泡排序:假设一个数组中有10个数字,从左边开始