Description

Dou Nai is an excellent ACM programmer, and he felt so tired recently that he wants to release himself from the hard work. He plans a travel to Xin Jiang .With the influence of literature, he wishes to visit Tian Chi, Da Ban Town, Lou Lan mysterious town , Yi Li , and other sights that also have great attraction to him. But the summer vocation time is not long. He must come back before the end of the summer vocation. For visiting more sights and all the necessary sights, he should make a thorough plan. Unfortunately, he is too tired to move, so you must help him to make this plan. Here are some prerequisites: there are two ways of transportation, bus and train, and velocity of the bus is 120km/h and the train is 80km/h. Suppose the travel is started from Urumuqi (point ), and the end of the travel route is Urumuqi too. You need to spend some time to visit the sights, but the time of each visit is not always equal. Suppose we spend  hours on traveling every day.
Input There are several test cases. For each case, the first line is three integers N, M and K. N (<=n<=) is the number of sights, M(<=M<=N) is total sights he must arrived (sight is always must be arrived) and K is total traveling time (per day). The second line is M integers which sights he must visited. The third line is N integers, the ith integer means the time he will stay in the sight i (per hour). Then several lines follow. Each line is four integers x, y, len and kind, <=x, y<=n, <len<=, means there is a bidirectional path between sights x and y, the distance is len, kind= means x and y are connected by train, kind= is by bus.
x=y=len=kind= means end of the path explanation.
N=M=K= means end of the input.
Output For each case, output maximum sights he will travel with all necessary sights visited or "No Solution" if he can't travel all the sights he like best in time.
Sample Input Sample Output No Solution

题目

  新疆地图……突然有点想家。

  题目大意:一个人在新疆旅游,有几个地方他必须去,剩下去的越多越好,有时间限制。他从乌市出发最后回到乌市,城市之间有火车或大巴,用的时间不一样。

  芒果君:这道题处理起来有点麻烦,但不难理解,算是状压DP的入门。先用floyd求最短路,然后进行记忆化搜索(DP和记搜搭配很强的,之前那道IOI的树型DP就是),枚举+松弛,多看几遍就能懂了233333333

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define inf 1<<29
using namespace std;
double mp[][],cost[],dp[<<][];
int n,m,k,ans,tar;
void init()
{
ans=tar=;
for(int i=;i<n;++i){
for(int j=;j<n;++j) mp[i][j]=inf;
mp[i][i]=;
}
for(int i=;i<(<<n);++i)
for(int j=;j<n;++j)
dp[i][j]=inf;
}
void floyd()
{
for(int k=;k<n;++k)
for(int i=;i<n;++i)
for(int j=;j<n;++j)
mp[i][j]=min(mp[i][j],mp[i][k]+mp[k][j]);
}
int sta(int x)
{
int t=x,sum=;
while(t){
if(t&) sum++;
t>>=;
}
return sum;
}
double dfs(int x,int y)
{
if(dp[x][y]!=inf) return dp[x][y];
double t=inf;
for(int i=;i<n;++i) if(x&(<<i)&&i!=y) if(i||(x^(<<y))==) t=min(t,dfs(x^(<<y),i)+mp[i][y]+cost[y]);
if((tar&x)==tar&&(t+mp[y][])<=k) ans=max(ans,sta(x));
return dp[x][y]=t;
}
int main()
{
int x,y,op,t;
double len;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
if(!n&&!m&&!k) break;
init();
k*=;
for(int i=;i<m;++i){
scanf("%d",&t);
tar|=<<(t-);
}
for(int i=;i<n;++i) scanf("%lf",&cost[i]);
while(scanf("%d%d%lf%d",&x,&y,&len,&op)!=EOF){
if(!x&&!y&&!len&&!op) break;
x--,y--;
mp[x][y]=mp[y][x]=min(mp[x][y],len/(80.0+op*40.0));
}
floyd();
dp[][]=cost[];
for(int i=;i<n;++i)
dfs((<<n)-,i);
if(ans>) printf("%d\n",ans);
else puts("No Solution");
}
return ;
}

  

POJ 3229:The Best Travel Design的更多相关文章

  1. poj 3229 The Best Travel Design ( 图论+状态压缩 )

    The Best Travel Design Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1359   Accepted: ...

  2. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  3. LeetCode 622:设计循环队列 Design Circular Queue

    LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素 ...

  4. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  5. POJ 2100:Graveyard Design(Two pointers)

    [题目链接] http://poj.org/problem?id=2100 [题目大意] 给出一个数,求将其拆分为几个连续的平方和的方案数 [题解] 对平方数列尺取即可. [代码] #include ...

  6. POJ 3580:SuperMemo(Splay)

    http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...

  7. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  8. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

  9. POJ 3436:ACM Computer Factory(最大流记录路径)

    http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...

随机推荐

  1. BZOJ 1299: [LLH邀请赛]巧克力棒 【SG函数/博弈分析/高斯消元】

    因为太懒,放个博客 我只写了O(2n)O(2^n)O(2n)的 CODE #include <cstdio> int n, x[15]; int main () { for(int T = ...

  2. python manage.py makemigrat Please select a fix: 1) Provide a one-off default now (will be set on all existing rows with a null value for this column) 2) Quit, and let me add a default in models.py

    更新models字段 出现的问题: $ python manage.py makemigrations None You are trying to add a non-nullable field ...

  3. [Number]js中数字存储(0.1 + 0.2 !== 0.3)

    和其他编程语言(如 C 和 Java)不同,JavaScript 不区分整数值和浮点数值, 所有数字在 JavaScript 中均用浮点数值表示,遵循IEEE754标准,在进行数字运算的时候要特别注意 ...

  4. LibreOJ #102. 最小费用流

    二次联通门 : LibreOJ #102. 最小费用流 /* LibreOJ #102. 最小费用流 Spfa跑花费 记录路径 倒推回去 */ #include <cstring> #in ...

  5. LOJ166 拉格朗日插值 2【卷积,NTT】

    题目链接:LOJ 题目描述:输入多项式的次数$n$,一个整数$m$和$f(0),f(1),f(2),\ldots,f(n)$,输出$f(m),f(m+1),f(m+2),\ldots,f(m+n)$ ...

  6. windows游戏编程X86 (内存)寄存器相关的基本概念

    本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/22446971 作者:jadeshu   邮箱: jades ...

  7. kubernetes案例 tomcat+mysql

    该文章参考<kubernetes 权威指南> 环境: [root@master tomcat-mysql]# kubectl get nodesNAME      STATUS    AG ...

  8. 【ElasticSearch+NetCore 第二篇】Nest封装

    using Elasticsearch.Net; using Nest; using System; using System.Collections.Generic; using System.Li ...

  9. spring中文参考指南

    主要是4.x版本的 比较全面的:https://muyinchen.gitbooks.io/spring-framework-5-0-0-m3/content/3.5-bean/3.5.4-reque ...

  10. Linux使用iptables设置黑白名单

    使用ipset工具 1,下面我先说下iptables的基本配置规则,然后再说ipset以下使用C7 x86_64为实验环境CentOS7默认的防火墙不是iptables,而是firewalle.如果你 ...