北京1009 hdu4049 Tourism Planning DP初始化
来源:互联网 发布:管理系统软件的软件 编辑:程序博客网 时间:2024/04/28 18:24
Tourism Planning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 395 Accepted Submission(s): 168
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.
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.
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 1101550 55 03 230 5024 4840 7035 200 4 14 0 51 5 02 2100 10050 5050 500 2020 00 0
Sample Output
541STAY HOME
Source
The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest
Recommend
lcy
/*犯的错误:开始没有初始化,后面觉得某个人一直走到最后会是正的,就一定要走到最后*/#include<string.h>#include<iostream>#include <stdio.h>#include <memory.h>using namespace std;//typedef long long LL;typedef __int64 LL;const int maxn=1<<11;LL A[11][11],B[11],g[11][11],dp[12][maxn],w[12][maxn],ww[maxn][maxn],m,n;LL Cal(){LL i1,j1,k1,ii,kk,i,j,k,a[15];for(i=0;i<m;i++)for(j=0;j<1<<n;j++)dp[i][j]=-100000000;memset(w,0,sizeof(w));for(j=0;j<1<<n;j++){i=j,ii=0,k=0;while(i){if(i&1)a[ii++]=k;k++;i=i>>1;}for(kk=0;kk<m;kk++){for(i=0;i<ii;i++)w[kk][j]+=A[a[i]][kk]-B[kk];for(i=0;i<ii;i++)for(k=i+1;k<ii;k++)w[kk][j]+=g[a[i]][a[k]];}}for(j=0;j<1<<n;j++)dp[0][j]=w[0][j];for(i=0;i<1<<n;i++){for(k=1,j=0;j<1<<n;j++)if((j|i)==i)ww[i][k++]=j;ww[i][0]=k;}for(i1=1;i1<m;i1++)//在i1点,在i1-1点剩的人的二进制表示为k1{for(j1=0;j1<1<<n;j1++){for(k1=1;k1<ww[j1][0];k1++){ii=ww[j1][k1];if(dp[i1][ii]<dp[i1-1][j1]+w[i1][ii])dp[i1][ii]=dp[i1-1][j1]+w[i1][ii];}}}for(kk=0,i=0;i<1<<n;i++)if(dp[m-1][i]>kk) kk=dp[m-1][i];return kk;}void Init(){ LL i,j; for(i=0;i<m;i++)//每个人进所需的钱 scanf("%I64d",&B[i]); for(i=0;i<n;i++)//i人到j地方的兴趣 for(j=0;j<m;j++)scanf("%I64d",&A[i][j]); for(i=0;i<n;i++)//i与j同时进再加的兴趣 for(j=0;j<n;j++) scanf("%I64d",&g[i][j]);}int main(){LL ii;while(scanf("%I64d%I64d",&n,&m)!=EOF){if(n==0&&m==0) break;Init();ii=Cal();if(ii<=0) printf("STAY HOME\n");else printf("%I64d\n",ii);}return 0;}
- 北京1009 hdu4049 Tourism Planning DP初始化
- HDU4049:Tourism Planning(状态压缩)
- 2011 Asia Beijing Regional Online Contest-1010 hdu4049 Tourism Planning
- Tourism Planning (状态dp)
- 北京赛区网选 J Tourism Planning(状态压缩DP或最大权闭合图)
- HDU 4049 Tourism Planning 状态压缩(DP)
- HDOJ 4049 Tourism Planning(状态压缩DP)
- HDU 4049 Tourism Planning (状压dp 详解)
- hdu 4049 - Tourism Planning
- hdu4049(状压dp)
- HDU4049【状压DP】
- hdu4049之状态压缩dp
- HDU 4049 Tourism Planning(动态规划)
- 【树DP】BZOJ3836[Poi2014]Tourism
- Tourism
- hdu Employment Planning (dp)
- HDU1158:Employment Planning(DP)
- HDU1158_Employment Planning【DP】
- transformation XML 转换
- VB DataGridView中上移下移功能的实现
- JSON --- JAVA对象转换为json
- 经常使用到的字符串操作方法
- mdev的使用方法和原理
- 北京1009 hdu4049 Tourism Planning DP初始化
- 各种数据库查询前几条数据的方法
- tomcat 配置
- .net 缓存基本方法
- iptables
- TortoiseSVN客户端访问常见问题及相关原因分析
- sql trace基础
- 网页原型设计
- MFC界面控制