题目大概说要吃掉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 ;
}

最新文章

  1. 微软unity 注入mvc
  2. C#以管理员身份运行程序
  3. 经典算法和OJ网站(开发者必备-转)
  4. jq 解析josn字符串
  5. Linux nmap
  6. Linux C 程序 信号及信号的处理(19)
  7. [Everyday Mathematics]20150126
  8. VIM中文乱码
  9. H面试程序(15): 冒泡排序法
  10. Codeforces 489A SwapSort
  11. codeforces 659B Qualifying Contest
  12. python绝技 — 使用PyGeoIP关联IP地址和物理位置
  13. 【百度之星2014~初赛(第二轮)解题报告】JZP Set
  14. shell 中 if then语句中会跟着-ne -ge之类的参数的含义
  15. 为什么我们要使用int类型来保存时间类型的数据。
  16. 【css技能提升】完美的 Sticky Footer 布局
  17. C语言实现简单CMDShell
  18. Executor简介
  19. How to Pronounce EVERY
  20. lua中table如何安全移除元素

热门文章

  1. 解决xib约束冲突
  2. 项目之solr全文搜索工具之创建项目索引库
  3. Rabbitmq实现负载均衡与消息持久化
  4. 关于logcat日志
  5. RST_n的问题
  6. 【转载】 Pyqt QStackedWidget堆栈窗体
  7. Elasticsearch在Windows下的安装
  8. AOJ673 聪明的输入法(字典树)
  9. git push 使用总结
  10. Java获取当前时间年月日、时间格式化打印、字符串转日期