Tourism Planning


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1051    Accepted Submission(s): 460

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
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  4050 4044 4042 4048 4047 
 

题目大意:

输入描述:

第一行两个数字表示,有n个人,m个城市

接下来 m个数字表示每个人参观这些城市的花费

接下来n行m列表示每个人参观每个城市得到的满意度

接下来n行n列表示每参观一个城市互相之间的影响的额外满意度,Bij (1<=i<=N, 1<=j<=N), 0<=Bij<=1000, Bij=0 if i=j, Bij=Bji.

你可以安排这n个人中的任意多个依次参观这m个城市0~m-1,中途也可以让一个人退出,退出后不能再回来,问你最大的值?

值 = 每个人参观每个城市得到的满意度的和 + 互相之间的影响增加的满意度和 - 参观花费和 。

解题思路:

这题的核心是DP

(1)因为n<=10 ,m<=10 ,数据比较小,可以考虑比较暴力的做法,DP就是一个很好的暴力。

(2)很容易就想到这样的DP方程 DP[sum][k]=max{ DP[son][k+1] } + value[sum][k];

sum 就是用2进制表示的有哪些人,son就是sum的子状态,表示sum中一些人半途离开了还剩下的人,

k表示当前是在访问到哪个城市了,DP[sum][k]记录的是在这个状态下要求的最大值。

当有sum这些人访问到k这个城市时候,这时候中途退了一些人,转移到了son这些人,k+1城市 这个状态

转移的花费就是 sum这些人在k这个城市获得的总值,记为 value[sum][k]。

(3)唯一有点麻烦的就是value[sum][k]的数据预处理,这个暴力枚举。

解题代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const int maxn=11;
int n,m;//n people,m cities
int cost[maxn],a[maxn][maxn],b[maxn][maxn];
int dp[(1<<maxn)][maxn],vis[(1<<maxn)][maxn],val[(1<<maxn)][maxn],marked; void input(){
marked++;
for(int i=0;i<m;i++) scanf("%d",&cost[i]);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
scanf("%d",&b[i][j]);
}
}
for(int i=0;i<m;i++){
for(int sum=0;sum<(1<<n);sum++){
val[sum][i]=0;
for(int p1=0;p1<n;p1++){
if( !((1<<p1)&sum) ) continue;
for(int p2=0;p2<p1;p2++){
if( (1<<p2)&sum ){
val[sum][i]+=b[p1][p2];
}
}
val[sum][i]+=a[p1][i]-cost[i];
}
}
}
} int DP(int sum,int k){
if(k>=m) return 0;
if(vis[sum][k]==marked) return dp[sum][k];
int ans=0;
for(int x=sum;x!=0;x=(x-1)&sum ){//for every son state
int tmp=DP(x,k+1)+val[sum][k];
if(tmp>ans) ans=tmp;
}
vis[sum][k]=marked;
return dp[sum][k]=ans;
} void solve(){
int ans=0;
for(int i=0;i<(1<<n);i++){
if(DP(i,0)>ans) ans=DP(i,0);
}
if(ans==0) printf("STAY HOME\n");
else printf("%d\n",ans);
} int main(){
while(scanf("%d%d",&n,&m)!=EOF && (n||m) ){
input();
solve();
}
return 0;
}

版权声明:欢迎关注我的博客,本文为博主toyking原创文章,未经博主允许不得转载。

HDU 4049 Tourism Planning(动态规划)的更多相关文章

  1. hdu 4049 Tourism Planning [ 状压dp ]

    传送门 Tourism Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. HDU 4049 Tourism Planning(状压DP)题解

    题意:m个城市,n个人,让这n个人按固定顺序走遍m个城市.每个城市有一个单人票价pi.每个人在每个城市能获得vij的价值.如果多个人在同一城市,那么会额外获得价值,给出一张n * n价值表,额外价值为 ...

  3. Tourism Planning(HDU 4049状压dp)

    题意:n个朋友去游览m个城市,给出每个人对每个城市的兴趣值,和每人去每个城市的花费,如果两人在一个城市有一个价值,若多于2人这这个价值是任意两人产生价值的总和.在去每个城市的过程中人可以随便离开,也可 ...

  4. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  5. HDU 2059 龟兔赛跑(动态规划)

    龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  6. HDU 3634 City Planning (离散化)

    City Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. HDU 2103 Family planning

    http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,there are so m ...

  8. hdu 2059:龟兔赛跑(动态规划 DP)

    龟兔赛跑 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  9. hdu 3008:Warcraft(动态规划 背包)

    Warcraft Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

随机推荐

  1. idea上实现github代码同步

    1.先将github远程仓库clone到本地 2.将本地仓库中的项目导入到idea中 3.如果你的项目代码不是放在仓库的根目录下,idea会识别到你的项目是在git仓库目录下,必须点击add root ...

  2. Scrum 1.0

    1.确定选题. 应用NABCD模型,分析你们初步选定的项目,充分说明你们选题的理由. 录制为演说视频,上传到视频网站,并把链接发到团队博客上. 项目:一个售书网站(O2O) 下面是NABCD模型: 1 ...

  3. C#字符串的恒定性

    string str1="aa"; string str2="aa"; str1,str2,变量所指向的堆空间的地址是一样的.栈空间的内容是不一样的. //ne ...

  4. 迭代接口的IEnumerator

    我们经常在工作中用到对List,Dictionary对象的Foreach遍历,取出每一项. 其实这个接口很简单,只有一个属性2个方法. [ComVisible(true), Guid("49 ...

  5. Winform开发框架之权限管理系统功能介绍

    权限管理系统的重要特性总结: 1) 高度集成的权限系统.独立模块,能快速整合使用.2) 符合权限的国际通用标准,基于RBAC(基于角色的访问控制)的角色权限控制.3) 多数据库架构支持,内置支持Sql ...

  6. 查询分页的几种Sql写法

    查询分页的几种Sql写法 摘自:http://www.cnblogs.com/zcttxs/archive/2012/04/01/2429151.html 1.创建测试环境,(插入100万条数据大概耗 ...

  7. C#中 导入和导出Excel的方法

    using System.Data; using System.Data.OleDb; /// <summary> /// Excel转为DataTable /// </summar ...

  8. asp.net 前台绑定后台变量方法总结:<%= %> 和<%# %>的区别

    经常会碰到在前台代码中要使用(或绑定)后台代码中变量值的问题.一般有<%= str%>和<%# str %>两种方式,这里简单总结一下.如有错误或异议之处,敬请各位指教.  一 ...

  9. 线段树的区间更新---A Simple Problem with Integers

    POJ   3468 Description 给出了一个序列,你需要处理如下两种询问. "C a b c"表示给[a, b]区间中的值全部增加c (-10000 ≤ c ≤ 100 ...

  10. [moka同学笔记]yii2.0 dropdownlist的简单使用(一)

    1.controller控制中 $modelCountrytelCode = CountryTelCode::find()->orderBy('id DESC')->all(); $tel ...