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. The method format(String, Object[]) in the type String is not applicable for the arguments

    今天,我弟遇到一个有意思的错误~ 程序: package com.mq.ceshi1; public class StringFormat { public static void main(Stri ...

  2. 5、Spring Boot 2.x 启动原理解析

    1.5 Spring Boot 启动原理解析 前言 前面几章我们见识了SpringBoot为我们做的自动配置,确实方便快捷,但是对于新手来说,如果不大懂SpringBoot内部启动原理,以后难免会吃亏 ...

  3. 使用docker 起容器配置负载均衡(加权)

    首先要准备三个nginx的容器: 第二个容器: 第三个容器: 进入第一个容器(主容器)  要配置的容器(docker exec -it 容器id /bin/bash)  vi/etc/nginx/ng ...

  4. 【题解】士兵训练-C++

    题目DescriptionN个士兵排成一队进行军事训练,每个士兵的等级用1…K范围内的数来表示,长官每隔1小时就随便说出M个等级a1,a2…am(1≤ai≤K,M个等级中允许有重复),如果这M个等级组 ...

  5. Vue Parent Send Ajax Data to Child Component

    Vue 父组件ajax异步更新数据,子组件props获取不到 2018年06月26日 09:25:06 哎哟嘿 阅读数 3585   当父组件  axjos  获取数据,子组件使用  props  接 ...

  6. 详解Kafka: 大数据开发最火的核心技术

    详解Kafka: 大数据开发最火的核心技术   架构师技术联盟 2019-06-10 09:23:51 本文共3268个字,预计阅读需要9分钟. 广告 大数据时代来临,如果你还不知道Kafka那你就真 ...

  7. [POI2010]MOT-Monotonicity 2

    洛谷题目链接 动态规划$+$线段树 题目链接(洛谷) 首先,先要明确一点,当我们填了第$i$位时,自然下一位的符号也就出来了 那么我们可以分情况讨论: $1.$当下一位是$>$时:我们可以建一棵 ...

  8. win10以及ubuntu下设置pip源

    问题描述:有一段时间下载python库的时候速度非常慢,想着提高安装python库的速度. window10下: 一:首先进入c盘的用户目录,如我的目录为C:\Users\felix. 二:创建名为p ...

  9. 【线性代数】6-4:对称矩阵(Symmetric Matrices)

    title: [线性代数]6-4:对称矩阵(Symmetric Matrices) categories: Mathematic Linear Algebra keywords: Eigenvalue ...

  10. Linux下 Java 读取文件路径

    一般文件路径在windows中用 \ 表示,但是在其他系统平台下比如linux中就不是 \ 所以java给我们提供了一个与平台无关的表示路径的常量 File.separator在windows中则表示 ...