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. 009_STM32程序移植之_内部falsh

    flash  模拟  EEPROM  实验 1. 测试环境:STM32C8T6 2. 测试接口: 3. 串口使用串口一,波特率9600 单片机引脚------------CH340引脚 VCC---- ...

  2. tinymce实现ctrl+v粘贴word图片并上传

    tinymce是很优秀的一款富文本编辑器,可以去官网下载.https://www.tiny.cloud 这里分享的是它官网的一个收费插件powerpaste的旧版本源码,但也不影响功能使用. http ...

  3. CF103D Time to Raid Cowavans 根号分治+离线

    题意: 给定序列 $a,m$ 次询问,每次询问给出 $t,k$. 求 $a_{t}+a_{t+k}+a_{t+2k}+.....a_{t+pk}$ 其中 $t+(p+1)k>n$ 题解: 这种跳 ...

  4. WEB测试重点及视频教程

    WEB测试重点如下: 1.WEB测试基础-2.理解网络协议-3.HTTP协议详解-4.WEB前段分析-5WEB安全性测试-6.WEB兼容性及可用性测试. 1.通常需要承受长时间的大量操作,因此web项 ...

  5. c++ 数据类型长度

    #include <iostream> using namespace std; int main() { cout << "char: " << ...

  6. Node解析之----模块机制篇

    开篇前,我们先来看张图, 看node与W3C组织.CommonJS组织.ECMAScript之间的关系. Node借鉴来CommonJS的Modules规范实现了一套非常易用的模块系统,NPM对Pac ...

  7. PyTricks-How to Sort a Python dict

    字典的键值排序 import operator # 1表示按照值排序 xs = {"a": 4, "b": 3, "c": 2, " ...

  8. k-means和iosdata聚类算法在生活案例中的运用

    引言:聚类是将数据分成类或者簇的过程,从而使同簇的对象之间具有很高的相似度,而不同的簇的对象相似度则存在差异.聚类技术是一种迭代重定位技术,在我们的生活中也得到了广泛的运用,比如:零件分组.数据评价. ...

  9. 区间dp括号匹配

    POJ2955 匹配则加一,不需要初始化 //#include<bits/stdc++.h> #include<iostream> #include<cstdio> ...

  10. Linux 下基础命令

    Linux:开源 Ubuntu Centos Deepin Debian Linux mint ... 1.省钱 2.省资源 Linux由unix演化而来 Linux:开源 Unix: 闭源 sola ...