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. bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】

    把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max, ...

  2. [Swift通天遁地]一、超级工具-(8)地图视图MKMapView的常用代理方法

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. Django day 36 支付宝支付,微信推送

    一:支付宝支付, 二:微信推送

  4. Linux学习笔记之Linux系统启动过程

    Linux系统的启动过程可以分为五个阶段: 内核的引导 运行init 系统初始化 建立终端 用户登录系统 1.内核引导: 当计算机打开电源后,首先进行BIOS开机自检,按照BIOS中设置的启动设备(一 ...

  5. [C++ STL] 各容器简单介绍

    什么是STL? 1.STL(Standard Template Library),即标准模板库,是一个高效的C++程序库. 2.包含了诸多常用的基本数据结构和基本算法.为广大C++程序员们提供了一个可 ...

  6. 2017杭电多校06Rikka with Graph

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. Manacher HDOJ 3068 最长回文

    题目传送门 关于求解最长回文子串,有dp做法,也有同样n^2的但只用O(1)的空间,还有KMP,后缀数组?? int main(void) { ) == ) { ); memset (dp, fals ...

  8. 转 form表单中name和id区别

          HTML文本是由HTML命令组成的描述性文本,HTML命令可以说明文字.图形.动画.声音.表格.链接等.HTML的结构包括头部(Head).主体(Body)两大部分,其中头部描述浏览器所需 ...

  9. C# 自动批量导入图片到数据库中

    using Model; using System; using System.Collections.Generic; using System.Data; using System.Data.Sq ...

  10. 无法连接到已配置的web服务器

    问题:如题,asp.net WebForm的项目,在vs中选择aspx文件在浏览器中查看时候回报该错误. 网上最多的解决方案是防火墙的原因,说关闭防火墙就可以了.但问题是我另一个项目没有问题啊,所以不 ...