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. javascript逻辑非(!/!!)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. SQL Server report server使用

    1.配置share point網站來改動報表      打開Reporting Servers Configuration Manager,裏面有Web Service URL(http://loca ...

  3. ckeditor不能粘贴word的问题如何解决

    自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...

  4. 2018 Nowcoder Multi-University Training Contest 10

    Practice Link J. Rikka with Nickname 题意: 给出\(n\)个字符串,要求依次合并两个串\(s, t\),满足将\(t\)合并到\(s\)中变成\(r\),使得\( ...

  5. Java面向对象4(P~U)

    P    3-1 Point类的构造函数 (SDUT 2670) import java.util.Arrays; import java.util.Scanner; public class Mai ...

  6. Grafana +Zabbix 系列二

    Grafana +Zabbix 系列二 Grafana 简介补充 Grafana自身并不存储数据,数据从其他地方获取.需要配置数据源 Grafana支持从Zabbix中获取数据 Grafana优化图形 ...

  7. 面试题_Spring高级篇

    Spring高级篇 1.什么是 Spring 框架? Spring 框架有哪些主要模块?  Spring 框架是一个为 Java 应用程序的开发提供了综合.广泛的基础性支持的 Java 平台. Spr ...

  8. Razor字符串处理

    需要注意的是低版本是不支持C# 6语法中的string interpolation的 <label> @if (!string.IsNullOrEmpty(Model.BudgetValu ...

  9. 使用hibernate利用实体类生成表和利用表生成实体类

    1,配置数据库,这里以oracle数据库为例.点击右侧Database图标:

  10. 慎用array_filter函数

    array_filter (PHP 4 >= 4.0.6, PHP 5, PHP 7) array_filter - 用回调函数过滤数组中的单元 说明 array array_filter (  ...