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 ;
}

  

最新文章

  1. mssql 字增自段怎样重置(重新自增)|清空表已有数据
  2. PHP计算一年有多少周,每周开始日期和结束日期
  3. 插入排序---希尔插入排序算法(Javascript版)
  4. ASIHTTPRequest类库简介和使用说明
  5. iis 重新注册 .net 方法
  6. C# httprequest post 内容有百分号,部分特殊字符乱码问题
  7. linux概念之时间与时区
  8. mysql主从复制-linux版本
  9. trigger,triggerhandler模拟事件
  10. HDU5348
  11. Comprehensive learning path – Data Science in Python深入学习路径-使用python数据中学习
  12. Apriori算法
  13. chrome浏览器强制采用https加密链接
  14. xxe漏洞的学习与利用总结
  15. ptyhon 编程基础之函数篇(二)-----返回函数,自定义排序函数,闭包,匿名函数
  16. Element ui表格展示图片问题
  17. 加速scp传输速度
  18. Solr 07 - Solr从MySQL数据库中导入数据 (Solr DIH的使用示例)
  19. How Tomcat works — 一、怎样阅读源码
  20. Spring MVC 知识点整理

热门文章

  1. 添加QQ群
  2. 012_STM32程序移植之_内部flash开机次数管理lib库建立
  3. Activiti服务类- RuntimeService服务类
  4. SpingMVC入门
  5. [USACO15DEC] 最大流Max Flow &amp;&amp; Tarjan 线性 LCA 教学?
  6. RNN(二)——基于tensorflow的LSTM的实现
  7. 微信小程序之简单记账本开发记录(五)
  8. Postgresql - MATERIALIZED VIEW
  9. 无法访问com.alibaba.fastjson.parser.deserializer.PropertyProcessable
  10. 01-背包---P2663 越越的组队