A Journey to Greece

Time Limit: 5000ms
Memory Limit: 262144KB

This problem will be judged on CodeForcesGym. Original ID: 100753A
64-bit integer IO format: %I64d      Java class name: (Any)

 
解题:状压dp
 #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn = ;
struct arc {
int to,cost,next;
arc(int x = ,int y = ,int z = -) {
to = x;
cost = y;
next = z;
}
} e[maxn*];
int head[maxn],hs[maxn],tot,N,P,M,G,T;
void add(int u,int v,int cost) {
e[tot] = arc(v,cost,head[u]);
head[u] = tot++;
}
priority_queue<pii,vector< pii >,greater< pii > >q;
int d[][maxn];
bool done[maxn];
void dijkstra(int S) {
while(!q.empty()) q.pop();
int s = hs[S];
memset(d[s],0x3f,sizeof d[s]);
q.push(pii(d[s][S] = ,S));
memset(done,false,sizeof done);
while(!q.empty()) {
int u = q.top().second;
q.pop();
if(done[u]) continue;
done[u] = true;
for(int i = head[u]; ~i; i = e[i].next) {
if(d[s][e[i].to] > d[s][u] + e[i].cost) {
d[s][e[i].to] = d[s][u] + e[i].cost;
q.push(pii(d[s][e[i].to],e[i].to));
}
}
}
}
int city[],ttime[],dp[<<][][];
int main() {
int u,v,w;
while(~scanf("%d%d%d%d%d",&N,&P,&M,&G,&T)) {
memset(head,-,sizeof head);
bool zero = false;
for(int i = tot = ; i < P; ++i) {
scanf("%d%d",city + i,ttime + i);
hs[city[i]] = i;
if(city[i] == ) zero = true;
}
for(int i = ; i < M; ++i) {
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
for(int i = ; i < P; ++i) dijkstra(city[i]);
if(!zero){
hs[] = P;
dijkstra();
}
memset(dp,0x3f,sizeof dp);
for(int i = ; i < P; ++i){
dp[<<i][i][] = d[hs[]][city[i]] + ttime[i];
dp[<<i][i][] = T + ttime[i];
}
int st = (<<P);
for(int i = ; i < st; ++i){
for(int j = ; j < P; ++j){
if(((i>>j)&) == ) continue;
for(int k = ; k < P; ++k){
if((i>>k)&) continue;
dp[i|(<<k)][k][] = min(dp[i|(<<k)][k][],dp[i][j][] + d[j][city[k]] + ttime[k]);
dp[i|(<<k)][k][] = min(dp[i|(<<k)][k][],dp[i][j][] + T + ttime[k]);
dp[i|(<<k)][k][] = min(dp[i|(<<k)][k][],dp[i][j][] + d[j][city[k]] + ttime[k]);
}
}
}
bool wtx = false,poss = false;
for(int i = ; i < P && !wtx; ++i){
if(dp[st-][i][] + d[i][] <= G) wtx = true;
if(dp[st-][i][] + T <= G) poss = true;
if(dp[st-][i][] + d[i][] <= G) poss = true;
}
if(wtx) puts("possible without taxi");
else if(poss) puts("possible with taxi");
else puts("impossible");
}
return ;
}

CodeForcesGym 100753A A Journey to Greece的更多相关文章

  1. 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)

    $$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...

  2. CodeForcesGym 100502K Train Passengers

    Train Passengers Time Limit: 1000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...

  3. CF721C. Journey[DP DAG]

    C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input ou ...

  4. POJ2488A Knight's Journey[DFS]

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41936   Accepted: 14 ...

  5. 关于Hellas和Greece

    一直以来我就好奇,为什么希腊的中文名字“希腊”和英文名字”Greece”听起来都不像(就像“德国”不像“Germany”一样),而且,为什么在很多体育比赛中看到希腊运动员的衣服上都是“Hellas”, ...

  6. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  7. POJ2488-A Knight's Journey(DFS+回溯)

    题目链接:http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  8. codeforces 721C C. Journey(dp)

    题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  9. A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏

    A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...

随机推荐

  1. E2017614-hm

     pluck   n. 勇气,精神; 内脏; 快而猛的拉; 〈俚〉不及格;   vt. 拔掉; 采,摘; 鼓起(勇气等); 弹(乐器);  scope  n. (处理.研究事务的) 范围; 眼界,见识 ...

  2. SP2916 GSS5 - Can you answer these queries V

    给定一个序列.查询左端点在$[x_1, y_1]$之间,且右端点在$[x_2, y_2]$之间的最大子段和,数据保证$x_1\leq x_2,y_1\leq y_2$,但是不保证端点所在的区间不重合 ...

  3. P2470 [SCOI2007]压缩

    传送门 区间dp,记\(dp(l,r,t)\)表示区间\((l,r)\),\(t\)表示这个区间中能不能放\(M\).如果可以,枚举中间哪里放\(M\)来压缩.也可以不压缩,后面直接跟上去.如果左右重 ...

  4. P3573 [POI2014]RAJ-Rally

    传送门 很妙的思路 首先这是一个DAG,于是我们先在原图和反图上各做一遍,分别求出\(diss_i\)和\(dist_i\)表示从\(i\)点出发的最短路和以\(i\)为终点的最短路 我们考虑把点分为 ...

  5. HTML5常用知识点

    github代码:https://github.com/showkawa/H5C3/tree/master/html5 1.自定义属性 data- 1.1 可以给html里的所有DOM对象都可以添加一 ...

  6. FPGA基础入门篇(四) 边沿检测电路

    FPGA基础入门篇(四)--边沿检测电路 一.边沿检测 边沿检测,就是检测输入信号,或者FPGA内部逻辑信号的跳变,即上升沿或者下降沿的检测.在检测到所需要的边沿后产生一个高电平的脉冲.这在FPGA电 ...

  7. 我的周记2——“天道酬勤"

    Get 什么是JAVA  https://zhuanlan.zhihu.com/p/62717204 了解下HTTP 缓存机制 https://juejin.im/post/5a1d4e546fb9a ...

  8. 关于mfc添加热键

    对于mfc的添加热键的文章已经有很多了,我这里就简单的说一下并且说一些可能出的错误 首先在资源文件中添加ACCELERATOR然后在资源文件下的RC中找到ACCELERATOR的节点,打开后可以发现一 ...

  9. Quartz.Net学习笔记(2)-简介

    一.Quartz.Net是什么 1.来源 Quartz.Net是一个开源的作业调度框架: 2.下载地址 官网地址:http://www.quartz-scheduler.net/documentati ...

  10. ImmutableJS

    引用大神的一句话:(具体是谁自己问度娘) Shared mutable state is the root of all evil(共享的可变状态是万恶之源) -- Pete Hunt   JavaS ...