旅游(CSUST省赛选拔赛2+状压dp+最短路)
题目链接:http://csustacm.com:4803/problem/1016
题目:


思路:状压dp+最短路,比赛的时候有想到状压dp,但是最短路部分写挫了,然后就卡死了,对不起出题人~dis[i][j]表示状态i下目的地为j时的最短路。
代码实现如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;;
typedef pair<int, int> pii;
typedef unsigned long long ull; #define lson i<<1
#define rson i<<1|1
#define bug printf("*********\n");
#define FIN freopen("D://code//in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = ;
const int maxn = 2e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f; int n, m, u, v, w;
ll ans;
int val[maxn], vis[][maxn];
ll dis[][maxn]; struct edge {
int v, w;
edge(int v, int w) : v(v), w(w) {}
}; struct node {
int v, sta;
ll w;
node(int v, int sta, ll w) : v(v), sta(sta), w(w) {}
bool operator < (const node& x) const {
return w > x.w;
}
}; vector<edge> G[maxn]; void dij() {
memset(vis ,, sizeof(vis));
memset(dis, inf, sizeof(dis));
priority_queue<node> q;
q.push(node(, (<<val[]), ));
dis[<<val[]][] = ;
while(!q.empty()) {
node e = q.top(); q.pop();
int u = e.v, sta = e.sta;
if(vis[sta][u]) continue;
vis[sta][u] = ;
for(int i = ; i < G[u].size(); i++) {
int v = G[u][i].v, nw = sta | (<<val[v]);
ll w = G[u][i].w;
if(dis[nw][v] > dis[sta][u] + w) {
dis[nw][v] = dis[sta][u] + w;
q.push(node(v, nw, dis[nw][v]));
}
}
}
} int main() {
//FIN;
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d", &val[i]);
}
for(int i = ; i <= m; i++) {
scanf("%d%d%d", &u, &v, &w);
G[u].push_back(edge(v, w));
G[v].push_back(edge(u, w));
}
dij();
ans = min(dis[][], dis[][]);
printf("%lld\n", ans);
return ;
}
旅游(CSUST省赛选拔赛2+状压dp+最短路)的更多相关文章
- Codevs 2009 大dota英雄 2013年省队选拔赛辽宁(状压DP)
2009 大dota英雄 2013年省队选拔赛辽宁 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 话说退役后的生活好无聊啊,以 ...
- 6.28 NOI模拟赛 好题 状压dp 随机化
算是一道比较新颖的题目 尽管好像是两年前的省选模拟赛题目.. 对于20%的分数 可以进行爆搜,对于另外20%的数据 因为k很小所以考虑上状压dp. 观察最后答案是一个连通块 从而可以发现这个连通块必然 ...
- [欢乐赛]班服 状压DP
班服 (shirt.pas/.c/.cpp) 时间限制:1s:内存限制 128MB 题目描述: 要开运动会了,神犇学校的n个班级要选班服,班服共有100种样式,编号1~100.现在每个班都挑出了一些样 ...
- Codeforces 375C - Circling Round Treasures(状压 dp+最短路转移)
题面传送门 注意到这题中宝藏 \(+\) 炸弹个数最多只有 \(8\) 个,故考虑状压,设 \(dp[x][y][S]\) 表示当前坐标为 \((x,y)\),有且仅有 \(S\) 当中的物品被包围在 ...
- BZOJ 3812 主旋律 (状压DP+容斥) + NOIP模拟赛 巨神兵(obelisk)(状压DP)
这道题跟另一道题很像,先看看那道题吧 巨神兵(obelisk) 题面 欧贝利斯克的巨神兵很喜欢有向图,有一天他找到了一张nnn个点mmm条边的有向图.欧贝利斯克认为一个没有环的有向图是优美的,请问这张 ...
- BZOJ2595 [Wc2008]游览计划 【状压dp + 最短路】
题目链接 BZOJ2595 题解 著名的斯坦纳树问题 设\(f[i][j][s]\)表示点\((i,j)\)与景点联通状况为\(s\)的最小志愿者数 设\(val[i][j]\)为\((i,j)\)需 ...
- poj 3311 状压dp 最短路
C - Hie with the Pie Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
- nyoj1273 河南省第九届省赛_"宣传墙"、状压DP+矩阵幂加速
宣传墙 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做 ...
- 【BZOJ-1097】旅游景点atr SPFA + 状压DP
1097: [POI2007]旅游景点atr Time Limit: 30 Sec Memory Limit: 357 MBSubmit: 1531 Solved: 352[Submit][Sta ...
随机推荐
- Matlab里面.M文件不能运行,预期的图像也显示不出来的一个原因
matlab中function函数的函数名与保存的文件名需要一样: 函数名是GAconstrain,文件名保存成GAconstrain.m,不要使用复制时候产生副本GAconstrain(1).m.
- sphinx配置 + php
1. 为什么要使用Sphinx 假设你现在运营着一个论坛,论坛数据已经超过100W,很多用户都反映论坛搜索的速度非常慢,那么这时你就可以考虑使用Sphinx了(当然其他的全文检索程序或方法也 ...
- vue h render function & render select with options bug
vue h render function & render select with options bug https://github.com/xgqfrms/vue/issues/41 ...
- 【.Net】HttpClient 的使用
class Program { public static HttpClient Client; static HttpResponseMessage response; static void Ma ...
- hbase windows安装
下载目前最新版本 http://mirrors.hust.edu.cn/apache/hbase/stable/ 最新版本 hbase-1.2.6 1. 解压到D:\software\hbase-1. ...
- Contest 4
A:cf原题.当然是不是也没什么关系. #include<iostream> #include<cstdio> #include<cstdlib> #include ...
- 数百种编程语言,而我为什么要学 Python?
是应用率最高.长期霸占排行榜的常青藤 Java?是易于上手,难以精通的 C?还是在游戏和工具领域仍占主流地位的 C++?亦或是占据 Windows 桌面应用程序半壁江山的 C#?…… 我想,每个人可能 ...
- Docker学习笔记一:如何在线安装
一.Docker简介: Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后 ...
- 洛谷 P2053 [SCOI2007]修车 解题报告
P2053 [SCOI2007]修车 题目描述 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术 ...
- scala(三)
一.面向对象编程——类 1.定义一个简单的类 class HelloWorld { private var name = "leo" def sayHello() { print( ...