Codeforces 580D Kefa and Dishes(状压DP)
题目大概说要吃掉n个食物里m个,吃掉各个食物都会得到一定的满意度,有些食物如果在某些食物之后吃还会增加满意度,问怎么吃满意度最高。
- dp[S][i]表示已经吃掉的食物集合是S且刚吃的是第i个食物的最大满意度
。。没什么好说的
#include<cstdio>
#include<algorithm>
using namespace std; int val[],pairs[][];
long long d[<<][]; int getCnt(int s){
int cnt=;
for(int i=; i<; ++i){
if(s>>i&) ++cnt;
}
return cnt;
} int main(){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=; i<n; ++i){
scanf("%d",val+i);
}
int a,b,c;
while(k--){
scanf("%d%d%d",&a,&b,&c);
--a; --b;
pairs[a][b]=c;
}
for(int i=; i<n; ++i){
d[<<i][i]=val[i];
}
for(int s=; s<(<<n); ++s){
for(int i=; i<n; ++i){
if((s>>i&)==) continue;
for(int j=; j<n; ++j){
if(i==j || (s>>j&)==) continue;
d[s][i]=max(d[s][i],d[s^(<<i)][j]+val[i]+pairs[i][j]);
}
}
}
long long res=;
for(int s=; s<(<<n); ++s){
if(getCnt(s)!=m) continue;
for(int i=; i<n; ++i){
res=max(res,d[s][i]);
}
}
printf("%lld",res);
return ;
}
Codeforces 580D Kefa and Dishes(状压DP)的更多相关文章
- codeforces 580D Kefa and Dishes(状压dp)
题意:给定n个菜,每个菜都有一个价值,给定k个规则,每个规则描述吃菜的顺序:i j w,按照先吃i接着吃j,可以多增加w的价值.问如果吃m个菜,最大价值是多大.其中n<=18 思路:一看n这么小 ...
- 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 ...
- Codeforces ----- Kefa and Dishes [状压dp]
题目传送门:580D 题目大意:给你n道菜以及每道菜一个权值,k个条件,即第y道菜在第x道后马上吃有z的附加值,求从中取m道菜的最大权值 看到这道题,我们会想到去枚举,但是很显然这是会超时的,再一看数 ...
- Codeforces 580D Kefa and Dishes(状态压缩DP)
题目链接:http://codeforces.com/problemset/problem/580/D 题目大意:有n盘菜每个菜都有一个满意度,k个规则,每个规则由x y c组成,表示如果再y之前吃x ...
- CF580D Kefa and Dishes 状压dp
When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. Th ...
- 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
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces Round #363 LRU(概率 状压DP)
状压DP: 先不考虑数量k, dp[i]表示状态为i的概率,状态转移方程为dp[i | (1 << j)] += dp[i],最后考虑k, 状态表示中1的数量为k的表示可行解. #incl ...
- codeforces 8C. Looking for Order 状压dp
题目链接 给n个物品的坐标, 和一个包裹的位置, 包裹不能移动. 每次最多可以拿两个物品, 然后将它们放到包里, 求将所有物品放到包里所需走的最小路程. 直接状压dp就好了. #include < ...
- Codeforces 429C Guess the Tree(状压DP+贪心)
吐槽:这道题真心坑...做了一整天,我太蒻了... 题意 构造一棵 $ n $ 个节点的树,要求满足以下条件: 每个非叶子节点至少包含2个儿子: 以节点 $ i $ 为根的子树中必须包含 $ c_i ...
随机推荐
- Jquery的普通事件和on的委托事件
以click的事件为例: 普通的绑定事件:$('.btn').click(function(){})绑定 on绑定事件:$(documnet).on('click','btn2',function() ...
- C#的正则表达式
using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...
- Android 5.0 如何正确启用isLoggable(一)__使用详解
转自:http://blog.csdn.net/yihongyuelan/article/details/46409389 isLoggable是什么 在Android源码中,我们经常可以看到如下代码 ...
- MVC4 使用概述
1.Bundle使用: http://www.cnblogs.com/inline/p/3897256.html 2.MVC总结: http://www.cnblogs.com/xlhblogs/ar ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- less2
less2 @base-color: #000; @fore-color: darken(@base-color, 50%); @back-color: lighten(@base-color, 50 ...
- php判断当前的访问是手机还是电脑
<?php function check_wap() { if (isset($_SERVER['HTTP_VIA'])) return true; if (isset($_SERVER['HT ...
- php同步mysql两个数据库中表的数据
分别创建两个数据库和两张表study库-zone表teaching库-area表 //****SQL脚本****// 1.创建teaching数据库area数据表 create database te ...
- Linux gnome
一.主题风格网站:gnome-look.org.deviantart.com.Linux公社 我使用的主题是:http://gnome-look.org/content/show.php/OS+X+1 ...
- ado.net增删改查练习
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...