hdu 4049 Tourism Planning [ 状压dp ]

传送门

Tourism Planning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1115    Accepted Submission(s): 482


Problem Description
Several friends are planning to take tourism during the next holiday. They have selected some places to visit. They have decided which place to start their tourism and in which order to visit these places. However, anyone can leave halfway during the tourism and will never back to the tourism again if he or she is not interested in the following places. And anyone can choose not to attend the tourism if he or she is not interested in any of the places.
Each place they visited will cost every person certain amount of money. And each person has a positive value for each place, representing his or her interest in this place. To make things more complicated, if two friends visited a place together, they will get a non negative bonus because they enjoyed each other’s companion. If more than two friends visited a place together, the total bonus will be the sum of each pair of friends’ bonuses.
Your task is to decide which people should take the tourism and when each of them should leave so that the sum of the interest plus the sum of the bonuses minus the total costs is the largest. If you can’t find a plan that have a result larger than 0, just tell them to STAY HOME.

 

Input
There are several cases. Each case starts with a line containing two numbers N and M ( 1<=N<=10, 1<=M<=10). N is the number of friends and M is the number of places. The next line will contain M integers Pi (1<=i<=M) , 1<=Pi<=1000, representing how much it costs for one person to visit the ith place. Then N line follows, and each line contains M integers Vij (1<=i<=N, 1<=j<=M), 1<=Vij<=1000, representing how much the ith person is interested in the jth place. Then N line follows, and each line contains N integers Bij (1<=i<=N, 1<=j<=N), 0<=Bij<=1000, Bij=0 if i=j, Bij=Bji.
A case starting with 0 0 indicates the end of input and you needn’t give an output.

 

Output
For each case, if you can arrange a plan lead to a positive result, output the result in one line, otherwise, output STAY HOME in one line.

 

Sample Input
2 1 10 15 5 0 5 5 0 3 2 30 50 24 48 40 70 35 20 0 4 1 4 0 5 1 5 0 2 2 100 100 50 50 50 50 0 20 20 0 0 0

 

Sample Output
5 41 STAY HOME

 

Source
The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  4041 4043 4050 4044 4045 

 

 

130750532015-03-09 18:32:49Accepted4049405MS2120K3076 BG++czy

 

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cstring>
  4 #include <algorithm>
  5 #include <vector>
  6 #include <string>
  7 #define N 15
  8 
  9 using namespace std;
 10 
 11 int n,m;
 12 int p[N];
 13 int v[N][N];
 14 int b[N][N];
 15 int dp[N][ (1<<10) ];
 16 int ans;
 17 int tot;
 18 int happy[N][ (1<<10) ];
 19 
 20 vector<int> can[ (1<<10) ];
 21 
 22 int cal(int i,int o);
 23 int ok(int k,int o);
 24 
 25 void ini()
 26 {
 27     int i,j;
 28     ans=0;
 29     memset(dp,0,sizeof(dp));
 30     for(i=1;i<=m;i++){
 31         scanf("%d",&p[i]);
 32     }
 33     for(i=0;i<n;i++){
 34         for(j=1;j<=m;j++){
 35             scanf("%d",&v[i][j]);
 36         }
 37     }
 38     for(i=0;i<n;i++){
 39         for(j=0;j<n;j++){
 40             scanf("%d",&b[i][j]);
 41         }
 42     }
 43     int o;
 44     tot = (1<<n);
 45     for(i=1;i<=m;i++){
 46         for(o=0;o<tot;o++){
 47             dp[i][o]=-1000000000;
 48         }
 49     }
 50     //printf("  n=%d m=%d tot=%d\n",n,m,tot );
 51     for(i=1;i<=m;i++){
 52         for(o=0;o<tot;o++){
 53             happy[i][o]=cal(i,o);
 54         }
 55     }
 56 
 57     for(o=0;o<tot;o++){
 58         can[o].clear();
 59         for(int k=0;k<tot;k++){
 60             if(ok(k,o)==1){
 61                 can[o].push_back(k);
 62             }
 63         }
 64     }
 65 }
 66 
 67 int cal(int i,int o)
 68 {
 69     int re=0;
 70     int j,k;
 71     int cc=0;
 72     //printf("  i=%d o=%d\n",i,o );
 73     for(j=0;j<n;j++){
 74         if( (1<<j) & o ){
 75             cc++;
 76             re+=v[j][i];
 77         }
 78     }
 79     //printf(" 1   re=%d\n",re );
 80     for(j=0;j<n;j++){
 81         if( (1<<j) & o ){
 82             for(k=j+1;k<n;k++){
 83                 if( (1<<k) & o ){
 84                     re += b[j][k];
 85                 }
 86             }
 87         }
 88     }
 89     // printf("  2  re=%d\n",re );
 90     re -= p[i]*cc;
 91      //printf("   3 re=%d\n",re );
 92     //printf("  i=%d o=%d re=%d\n",i,o,re );
 93     return re;
 94 }
 95 
 96 int ok(int k,int o){
 97     int j;
 98     for(j=0;j<n;j++){
 99        // printf("    j=%d\n",j );
100         if( (1<<j) & o ){
101             if(  (  (1<<j) &k ) ==0 ){
102                 return 0;
103             }
104         }
105     }
106     return 1;
107 }
108 
109 void solve()
110 {
111     int o,j,i,k;
112     int te;
113     for(i=1;i<=m;i++){
114         //printf("  i=%d\n",i );
115         for(o=0;o<tot;o++){
116            // printf("   o=%d\n", o);
117             for(vector<int>::iterator it =can[o].begin();it != can[o].end();it++){
118            // for(k=0;k<tot;k++){
119                  //printf("   k=%d\n", k);
120                 k=*it;
121                // if(ok(k,o)==0) continue;
122                 
123                 //te=cal(i,o);
124                 te=happy[i][o];
125                 dp[i][o]=max(dp[i][o],dp[i-1][k]+te);
126                 //printf("    i=%d o=%d dp=%d\n", i,o,dp[i][o]);
127             }  
128         }
129     }
130 
131     i=m;
132     for(o=0;o<tot;o++){
133         //printf("  o=%d dp=%d\n",o,dp[m][o] );
134         ans=max(ans,dp[m][o]);
135     }
136 }
137 
138 void out()
139 {
140     if(ans<=0){
141         printf("STAY HOME\n");
142     }
143     else{
144         printf("%d\n", ans);
145     }
146 }
147 
148 int main()
149 {
150     while(scanf("%d%d",&n,&m)!=EOF){
151         if(n==0 && m==0) break;
152         ini();
153         solve();
154         out();
155     }
156 }

 

转载于:https://www.cnblogs.com/njczy2010/p/4324225.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/297936.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置

nginxPHPPHP-FPM(FastCGI)在Ubuntu上的安装和配置0 之前知识回顾&#xff1a; 1) 目前各种服务器HTTP Server对PHP的支持一共有三种&#xff1a; a.通过HTTPServer内置的模块来实现&#xff0c;例如Apache的mod_php5&#xff0c;类似的Apache内置的mod_perl可以对perl支持&…

有图有真相!这世界上,竟有人跟你长得一模一样!

全世界只有3.14 % 的人关注了爆炸吧知识你相信这个世界上有和你长得一模一样的人吗&#xff1f;我本来不信的看到这个摄影师的作品后真&#xff01;香&#xff01;冥冥之中&#xff0c;在平行宇宙在地球的另一端真的有另外一个你和你长得一模一样在生活&#xff0c;在呼吸老牌人…

python双除_python2和python3 中的除法的区别

1. python2中有/和//的除法区别&#xff1a;其中/的用法&#xff1a;>>>1/20即一个整数(无小数部分的数)被另外一个整数除&#xff0c;计算结果的小数部分被截除了&#xff0c;只留下了整数部分有时候&#xff0c;这个功能比较有用&#xff0c;譬如在做一些需要取位数…

两条线段的夹角 cesium_《原本》命题1.10 一条线段可以被分成两条相等的线段

命题1.10一条线段可以被分成两条相等的线段设&#xff1a;AB为一条直线。求作&#xff1a;平分为两条相等的线段。作等边三角形ABC(命题1.1)命题1.1已知一条线段可作一个等边三角形。作∠ACB的角平分线CD(命题1.9)命题1.9一个角可以切分成两个相等的角。那么&#xff1a;D 点就…

有关的命令linux,Linux与用户有关的命令

passwd命令passwd 命令用来修改您的密码。语法:语法是passwd [命令开关]命令开关:-a显示密码属性的所有项目。-l锁住密码。-d删除用户密码&#xff0c; 登录时将不是提示密码。-f强制用户在下次登录时候更改密码。示例:passwd直接输入 passwd 目录的时候允许您更改密码。 在输入…

Minimal API Todo Sample

Minimal API Todo SampleIntro.NET 6 Preview 4 开始引入了 Minimal API 到如今的 RC1&#xff0c;Minimal API 也完善了许多并且修复了很多BUG&#xff0c;之前也写过文章介绍&#xff0c;可以参考:ASP.NET Core 6 Minimal API &#xff0c;不过只是写了一个 Hello World, 最早…

WPF基础到企业应用系列7——深入剖析依赖属性(三)

八. 只读依赖属性 我们以前在对简单属性的封装中&#xff0c;经常会对那些希望暴露给外界只读操作的字段封装成只读属性&#xff0c;同样在WPF中也提供了只读属性的概念&#xff0c;如一些 WPF控件的依赖属性是只读的&#xff0c;它们经常用于报告控件的状态和信息&#xff0c;…

Web的结构组件

位于Web浏览器与Web服务器之间还有一些用于帮助他们进行事物处理的应用程序&#xff0c;如下所示。 代理 代理位于客户端和服务器之间&#xff0c;接受所有客户端的HTTP请求&#xff0c;并将这些请求转发给服务器。 缓存 Web缓存或代理缓存是一种特殊HTTP代理服务器&#xff0c…

从没想过从上帝视角看地球,竟美得如此震撼!

全世界只有3.14 % 的人关注了爆炸吧知识“ 当你从另一个角度俯瞰地球&#xff0c;你就能发现不一样的世界 。。。试想你现在飘起来了飘得越来越高&#xff0c;地球在你眼里慢慢变小现在&#xff0c;你看见的是此生从未见过的景色——《极简宇宙史》当想象力带我走向未知脑海…

双目三维重建_【光电视界】简单介绍双目视觉三维重构

今日光电有人说&#xff0c;20世纪是电的世纪&#xff0c;21世纪是光的世纪&#xff1b;知光解电&#xff0c;再小的个体都可以被赋能。欢迎来到今日光电&#xff01;----与智者为伍 为创新赋能----1、三维重构1.1、三维重构到底是什么&#xff1f;首先要了解立体匹配算法&…

交换网络中的sniffer讨论-基于交换网络的ARP spoofing sniffer

交换网络中的sniffer讨论->基于交换网络的ARP spoofing sniffer 转自--http://blog.csdn.net/zhangnn5/article/details/6810347 在阅读这篇文章之前&#xff0c;我假设你已经知道TCP/IP协议&#xff0c;ARP协议&#xff0c;知道什么是sniffer等基本网络知识。在一般的局域网…

mendelay为什么安装不了_你为什么消防验收过不了?消防管道安装错误图集

来源&#xff1a;水电工论坛如有侵权&#xff0c;请联系删除消防管道安装如果一次没做好&#xff0c;验收不通过的话重新返工将对工程进度造成很大的影响&#xff0c;所以在施工时一定要注意以下的错误一定不能出现。2个沟槽卡箍间管段未设置支架立管角钢支架安装时应平面朝上管…

.NET 6 中的HTTP 3支持

dotnet团队官方博客发布了一篇HTTP3的文章&#xff1a;HTTP/3 support in .NET 6&#xff1a;https://devblogs.microsoft.com/dotnet/http-3-support-in-dotnet-6/。文章介绍了.NET 6 将预览支持HTTP3&#xff0c;.NET 7正式支持HTTP3&#xff0c;原因主要是HTTP/3 的 RFC 尚未…

JavaScript数组sort方法(数组排序)

数组对象的sort方法可以按照一定的顺序把数组元素重新排列起来。通常情况下&#xff0c;都是按照字母顺序排列的。JavaScript代码 <script type"text/javascript"> var arr ["HTML","CSS","JavaScript","DOM"]…

Lock与synchronized 的区别

2019独角兽企业重金招聘Python工程师标准>>> 多次思考过这个问题&#xff0c;都没有形成理论&#xff0c;今天有时间了&#xff0c;我把他总结出来&#xff0c;希望对大家有所帮助 1、ReentrantLock 拥有Synchronized相同的并发性和内存语义&#xff0c;此外还多了 …

python从入门到实践django_Django入门——《Python编程从入门到实践》

Django是一个Web框架——一套用于帮助开发交互式网站的工具。Django能够响应网页请求&#xff0c;还能让你更轻松地读写数据库、管理用户等。1、建立项目开始编写一个名为“学习笔记”的Web应用程序&#xff0c;让用户能够记录感兴趣的主题&#xff0c;并在学习每个主题的过程中…

linux 内核 三天吐血,编译安装——吐血经验,内附脚本

程序包编译安装&#xff1a;源码包&#xff1a;name-VERSION-release.src.rpmrpm由源码包安装后&#xff0c;使用rpmbuild命令制作成二进制格式的rpm包&#xff0c;而后再安装源代码–> 预处理–> 编译(gcc)–> 汇编–> 链接–> 执行源代码组织格式&#xff1a;…

mac编辑器coda使用小贴条

前言&#xff1a;最近用mac开发环境了&#xff0c;自然一天到晚用coda&#xff0c;可总是有不顺的地方&#xff0c;搜到这篇文章感觉像看到了知音人&#xff0c;实在是解决了我不少疑难问题啊。外文针对的coda版本较低&#xff0c;我总结的针对版本是version1.7.3 coda快捷键操…

我在 GitHub 上发现了一款骚气满满的字体!

全世界只有3.14 % 的人关注了爆炸吧知识转自&#xff1a;量子位&#xff0c;作者&#xff1a;栗体这个字体叫 Leon Sans&#xff0c;表面看去平平无奇。但事实上&#xff0c;它并不是普通的字体&#xff0c;体内蕴藏着魔力。Leon Sans 最特别的地方在于&#xff0c;字体是由代码…

PHP 接收 UDP包_php只能做网站?基于swoole+websocket开发双向通信应用

前言众所周知&#xff0c;PHP用于开发基于HTTP协议的网站应用非常便捷。而HTTP协议是一种单向的通信协议&#xff0c;只能接收客户端的请求&#xff0c;然后响应请求&#xff0c;不能主动向客户端推送信息。因此&#xff0c;一些实时性要求比较高的应用&#xff0c;如实时聊天、…