[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这么小 ...
随机推荐
- [黑金原创教程] FPGA那些事儿《数学篇》- CORDIC 算法
简介 一本为完善<设计篇>的书,教你CORDIC算法以及定点数等,内容请看目录. 贴士 这本教程难度略高,请先用<时序篇>垫底. 目录 Experiment 01:认识CORD ...
- Egret3D初步学习笔记三 (角色使用)
一 Unity中编辑角色 仍然使用unity4.7.1_Egret3D_Dll.unitypackage. 里面含有一个角色. 二 查看人物的动画 选中lingtong 属性面板里有个Animator ...
- phpStorm 显示行号
- 删除 oracle
C:\app\Administrator\product\11.2.0\client_1\deinstall 用这个批处理文件,会把oracle全部删除,除这个目录本身以外 .另外它不删除服务,即使服 ...
- 使用docx4j编程式地创建复杂的Word(.docx)文档
原文链接:Create complex Word (.docx) documents programatically with docx4j 原文作者:jos.dirksen 发表日期:2012年2月 ...
- https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic net::ERR_CONNECTION_TIMED_OUT问题解决
使用adminTLE时,有时候出现 https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic, ...
- Introduction to Structured Data json的2种形式 JAVA解析JSON数据 - JsonArray JsonObject
https://developers.google.com/search/docs/guides/intro-structured-data Structured data refers to kin ...
- 106 miles to Chicago---zoj2797(最短路问题,求概率,模板)
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemId=1797 题意是有 n 个点 m 条边,从a到b的不被抓的概率是p,让求从点 ...
- 【新业务搭建】竞争情报业务规划及体系构建的思考——By Team
竞争情报业务规划.体系构建 一.竞争情报业务定位——“做什么” 一)业务愿景.目标和原则 愿景:将情报工作融入到公司各个业务中,成为业务活动的灯塔 目标:直接支撑标杆学习(间接支撑三大战略).直接支持 ...
- 【查看】mysql 常规书写注意事项(那些坑)
mysql 常规书写注意事项,mysql注意事项 1. 注释: -- 后面一定要加一个空格,否则会报错 2.注释:/*! content */ 在mysql中是会执行的,但是其他数据库不会. 例 ...