题意翻译

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的更多相关文章

  1. CF580D Kefa and Dishes 状压dp

    When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. Th ...

  2. CF580D Kefa and Dishes 【状压dp】By cellur925

    题目传送门 友情链接:new2zydalao%%%  一篇优秀的状压文章 题目大意:$n$个菜有$k$个规则,如果kefa在吃完第$xi$个菜之后吃了第$yi$个菜(保证$xi$.$yi$不相等), ...

  3. CF580D Kefa and Dishes (状压DP)

    枚举最后食物 #include <iostream> #include <cstdio> #include <cstring> #include <algor ...

  4. 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 ...

  5. dp + 状态压缩 - Codeforces 580D Kefa and Dishes

    Kefa and Dishes Problem's Link Mean: 菜单上有n道菜,需要点m道.每道菜的美味值为ai. 有k个规则,每个规则:在吃完第xi道菜后接着吃yi可以多获得vi的美味值. ...

  6. codeforces 580D:Kefa and Dishes

    Description When Kefa came to the restaurant and sat at a table, the waiter immediately brought him ...

  7. codeforces 580D. Kefa and Dishes

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. Codeforces 580D Kefa and Dishes(状压DP)

    题目大概说要吃掉n个食物里m个,吃掉各个食物都会得到一定的满意度,有些食物如果在某些食物之后吃还会增加满意度,问怎么吃满意度最高. dp[S][i]表示已经吃掉的食物集合是S且刚吃的是第i个食物的最大 ...

  9. codeforces 580D Kefa and Dishes(状压dp)

    题意:给定n个菜,每个菜都有一个价值,给定k个规则,每个规则描述吃菜的顺序:i j w,按照先吃i接着吃j,可以多增加w的价值.问如果吃m个菜,最大价值是多大.其中n<=18 思路:一看n这么小 ...

随机推荐

  1. activemq 实战三 了解连接器的URI-Understanding connector URIs

    Before discussing the details of connectors and their role in the overall ActiveMQ architecture, it’ ...

  2. MQTT的学习研究(二)moquette-mqtt 的使用之mqtt broker的启动

    在MQTT 官网 (http://mqtt.org/software)中有众多MQTT的实现方式.具体参看官网,Moquette是基于Apache Mina 的模型的一个Java MQTT broke ...

  3. LeetCode——Lowest Common Ancestor of a Binary Search Tree

    Description: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given no ...

  4. js的声明提前

    由于js声明提前的作用,所以在js中后面定义的函数也可以再前面使用. 不过,项目中看到过这样的写法 var a = function(){}, b = function(){}; 这种写法使代码看上去 ...

  5. kubernetes创建yaml,pod服务一直处于 ContainerCreating状态的原因查找与解决

    最近刚刚入手研究kubernetes,运行容器的时候,发现一直处于ContainerCreating状态,悲了个催,刚入手就遇到了点麻烦,下面来讲讲如何查找问题及解决的 运行容器命令: kubectl ...

  6. [Music] Billboard Hot 100 Singles Chart 27th Jun 2015

    01 Wiz Khalifa - See You Again (Feat. Charlie P..> 30-Jul-2015 09:12 9247814 02 Taylor Swift - Ba ...

  7. oneThink发生错误,获取当前执行的SQL语句!

    echo D('AnswerInfoView')->getLastSql();die();

  8. pandas处理日期时间,按照时间筛选

    pandas有着强大的日期数据处理功能,本期我们来了解下pandas处理日期数据的一些基本功能,主要包括以下三个方面: 按日期筛选数据 按日期显示数据 按日期统计数据 运行环境为 windows系统, ...

  9. SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询

    这是来新公司写的第一篇文章,使用LEFT JOIN ON LIKE处理一下这种问题: SQL视图代码如下: CREATE View [dbo].[VI_SearchCN] AS --搜索产品的文件 ( ...

  10. CodeForces Roads not only in Berland(并查集)

    H - Roads not only in Berland Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d ...