博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4284 Travel(压缩DP,4级)
阅读量:5249 次
发布时间:2019-06-14

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

Travel

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2641    Accepted Submission(s): 724


Problem Description
  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
 
2 4 5 10 1 2 1 2 3 2 1 3 2 1 4 1 3 4 2 3 1 8 5 2 5 2 3 10 1 2 1 100 1 2 10000 1 2 100000 1
 

Sample Output
 
YES NO
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:            

预处理两点距离,然后压缩DP。

dp[mask][k];最后在k 走过状态mask

注意重边

#include 
#include
#include
#define FOR(i,a,b) for(int i=a;i<=b;++i)#define clr(f,z) memset(f,z,sizeof(f))#define ll(x) (1<
= g[1][ id[i] ] + D[i]) dp[ ll(i) ][i] = money - g[1][ id[i] ] - D[i] + C[i]; FOR(i,1,zzz)FOR(j,0,H-1)FOR(k,0,H-1) if(j != k && (i&ll(k)) && (i&ll(j)) && dp[ i^ll(j) ][k] != -1) { then = i^ll(j); if(dp[then][k] >= g[ id[k] ][ id[j] ] + D[j]) dp[i][j] = max(dp[i][j],dp[then][k] - g[ id[k] ][ id[j] ] - D[j] + C[j]); } bool flag=0; FOR(i,0,H-1) if(dp[zzz][i]>=g[ id[i] ][1]) flag=1; if(flag)puts("YES"); else puts("NO"); } } return 0;}

转载于:https://www.cnblogs.com/nealgavin/p/3797486.html

你可能感兴趣的文章
海量数据存储
查看>>
js中的try/catch
查看>>
[导入]玫瑰丝巾!
查看>>
自动从网站上面下载文件 .NET把网站图片保存到本地
查看>>
【识记】 域名备案
查看>>
STL uva 11991
查看>>
MY SQL的下载和安装
查看>>
自定义OffMeshLink跳跃曲线
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
简述spring中常有的几种advice?
查看>>
学习Redux之分析Redux核心代码分析
查看>>
ABAP 创建和调用WebService
查看>>
C# 实例化顺序
查看>>
CSS水平垂直居中总结
查看>>
委托又给我惹麻烦了————记委托链的取消注册、获取返回值
查看>>
ps怎么把白色背景变透明
查看>>
gource 安装教程
查看>>
字符串转 Boolean 的正确方式
查看>>
给你的网站404页面加上“宝贝寻亲”公益页面
查看>>
整理推荐的CSS属性书写顺序
查看>>