博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 4284 Travel(floyd+状压dp)
阅读量:5356 次
发布时间:2019-06-15

本文共 2520 字,大约阅读时间需要 8 分钟。

Travel

 

  PP loves travel. Her dream is to travel around country A which consists of N cities and M roads connecting them. PP has measured the money each road costs. But she still has one more problem: she doesn't have enough money. So she must work during her travel. She has chosen some cities that she must visit and stay to work. In City_i she can do some work to earn Ci money, but before that she has to pay Di money to get the work license. She can't work in that city if she doesn't get the license but she can go through the city without license. In each chosen city, PP can only earn money and get license once. In other cities, she will not earn or pay money so that you can consider Ci=Di=0. Please help her make a plan to visit all chosen cities and get license in all of them under all rules above. 
  PP lives in city 1, and she will start her journey from city 1. and end her journey at city 1 too. 

Input  The first line of input consists of one integer T which means T cases will follow. 

  Then follows T cases, each of which begins with three integers: the number of cities N (N <= 100) , number of roads M (M <= 5000) and her initiative money Money (Money <= 10^5) . 
  Then follows M lines. Each contains three integers u, v, w, which means there is a road between city u and city v and the cost is w. u and v are between 1 and N (inclusive), w <= 10^5. 
  Then follows a integer H (H <= 15) , which is the number of chosen cities. 
  Then follows H lines. Each contains three integers Num, Ci, Di, which means the i_th chosen city number and Ci, Di described above.(Ci, Di <= 10^5) 
Output  If PP can visit all chosen cities and get all licenses, output "YES", otherwise output "NO". 
Sample Input

24 5 101 2 12 3 21 3 21 4 13 4 231 8 52 5 23 10 12 1 1001 2 1000012 100000 1

Sample Output

YESNO
题意:1能否经过h个点并回到1处?在经过边时花费边权,第一次到达h中任意点时先花费后点权,再收获前点权,若在次过程中无法保证非负,输出NO。
先预处理出h个点之间两两的最短路,然后状压dp求出在满足限制下的最大收益,-1输出NO。
#include
#define MAX 105#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;int a[MAX][MAX],b[16][2];int dp[1<<15][16];int mp[16];int main(){ int t,n,m,mon,h,i,j,k; int x,y,z; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&m,&mon); memset(a,INF,sizeof(a)); for(i=1;i<=n;i++){ a[i][i]=0; } for(i=1;i<=m;i++){ scanf("%d%d%d",&x,&y,&z); if(a[x][y]==INF){ a[x][y]=z; a[y][x]=z; } else if(z
 
 

转载于:https://www.cnblogs.com/yzm10/p/9610323.html

你可能感兴趣的文章
python 用数组实现队列
查看>>
认证和授权(Authentication和Authorization)
查看>>
CSS3中box-sizing的理解
查看>>
传统企业-全渠道营销解决方案-1
查看>>
Lucene全文检索
查看>>
awk工具-解析1
查看>>
CRM product UI里assignment block的显示隐藏逻辑
查看>>
AMH V4.5 – 基于AMH4.2的第三方开发版
查看>>
Web.Config文件配置之配置Session变量的生命周期
查看>>
mysql导入source注意点
查看>>
linux下编译安装nginx
查看>>
ArcScene 高程不同的表面无法叠加
查看>>
[ONTAK2010] Peaks
查看>>
DLL 导出函数
查看>>
windows超过最大连接数解决命令
查看>>
12个大调都是什么
查看>>
angular、jquery、vue 的区别与联系
查看>>
javascript中sort()排序方法总结
查看>>
实现聊天界面的代码
查看>>
自己生成一个NDK的浅析
查看>>