URAL 1741 Communication Fiend dp
来源:互联网 发布:painter下载mac 编辑:程序博客网 时间:2024/06/05 15:25
题目链接:点击打开链接
#include <cstdio>#include <algorithm>#include <cstring>typedef long long ll;const ll Inf = (ll)(1e15);const int N = 10000 + 10;const int E = 10000 + 10;struct Edge {int v, cos, f, nex;Edge() {}Edge(int _v, int _cos, int _f, int _nex) {v = _v;cos = _cos;f = _f;nex = _nex;}};int g[N], idx;Edge eg[E];ll d[N][2];int n, m;void addedge(int u, int v, int len, int f) {eg[idx] = Edge(v, len, f, g[u]);g[u] = idx++;}ll dp(int dep, int fl) {if (d[dep][fl] >= 0)return d[dep][fl];d[dep][fl] = Inf;int to;for (int i = g[dep]; ~i; i = eg[i].nex) {to = eg[i].v;if (eg[i].f == 0) {d[dep][fl] = std::min(d[dep][fl], dp(to, 1) + eg[i].cos);} else if (eg[i].f == 1) {if (fl)continue;d[dep][fl] = std::min(d[dep][fl], dp(to, 0) + eg[i].cos);d[dep][fl] = std::min(d[dep][fl], dp(to, 1) + eg[i].cos);} else if (eg[i].f == 2) {d[dep][fl] = std::min(d[dep][fl], dp(to, fl) + eg[i].cos);}}return d[dep][fl];}void work() {int u, v, cos;char s[15];ll ans;idx = 0;memset(g, -1, sizeof g);while (m -- > 0) {scanf("%d%d%d%s", &u, &v, &cos, s);if (*s == 'L') {addedge(v, u, cos, 0);} else if (*s == 'P') {addedge(v, u, cos, 1);} else {addedge(v, u, cos, 2);}}memset(d, -1, sizeof d);d[1][1] = 0;ans = std::min(dp(n, 1), dp(n, 0));if (ans == Inf)puts("Offline");else {puts("Online");printf("%I64d\n", ans);}}int main() {while (~scanf("%d%d", &n, &m))work();return 0;}
0 0
- URAL 1741 Communication Fiend dp
- URAL - 1741 - Communication Fiend(dp)
- ural 1741 Communication Fiend
- URAL 1741 Communication Fiend
- URAL - 1741 Communication Fiend
- timus 1741. Communication Fiend URAL 解题报告 DP+读题
- Timus 1741. Communication Fiend
- Fiend
- Communication System(dp)
- [DP]poj1018 Communication System
- poj1018 Communication System dp
- pku 1018 Communication System dp
- POJ 1018 Communication System (DP)
- POJ 1018 Communication System dp
- POJ 1018:Communication System - DP
- POJ 1018Communication System(DP)
- poj 1018 Communication System(DP)
- Hex Fiend
- 线程栈和进程栈 区别
- 无线通信调制与解调浅析
- 传苹果公司10月21日发布新版iPad及操作系统
- lua string 库
- 链表、头指针、头结点
- URAL 1741 Communication Fiend dp
- Cognos函数(十二) - firstChild & lastChild
- poj 2886 Who Gets the Most Candies?(线段树)
- cpp-tests ActionManagerTest
- Android多媒体学习九:利用MediaRecorder类实现自己的音频录制程序
- HDU1171 Big Event in HDU
- arch普通用户无法进入X
- 啦啦熊励志篇
- Android 根据EditText搜索框ListView动态显示数据