URAL 1741 Communication Fiend
思路:
dp
状态:dp[i][1]表示到第i个版本为正版的最少流量花费
dp[i][0]表示到第i个版本为盗版的最少流量花费
初始状态:dp[1][0]=dp[0][0]=0
目标状态:min(dp[n][0],dp[n][1])
状态转移:见代码,注意如果是cracked版本,如果原来是盗版,转移后还是盗版
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e4+;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll dp[N][];
bool vis[N];
int head[N];
struct edge{
int to,w,f,next;
}edge[N];
int cnt=;
void add_edge(int u,int v,int w,int f){
edge[cnt].to=v;
edge[cnt].w=w;
edge[cnt].f=f;
edge[cnt].next=head[u];
head[u]=cnt++;
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
int n,m,x,y,d,t;
string s;
cin>>n>>m;
mem(head,-);
for(int i=;i<m;i++){
cin>>x>>y>>d>>s;
if(s[]=='L')t=;
else if(s[]=='P')t=;
else t=;
add_edge(x,y,d,t);
}
mem(dp,INF);
dp[][]=;
dp[][]=;
for(int i=;i<=n;i++){
for(int j=head[i];~j;j=edge[j].next){
if(edge[j].f==){
dp[edge[j].to][]=min(dp[edge[j].to][],dp[i][]+edge[j].w);
}
else if(edge[j].f==){
dp[edge[j].to][]=min(dp[edge[j].to][],min(dp[i][],dp[i][])+edge[j].w);
}
else if(edge[j].f==){
dp[edge[j].to][]=min(dp[edge[j].to][],dp[i][]+edge[j].w);
dp[edge[j].to][]=min(dp[edge[j].to][],dp[i][]+edge[j].w);
}
}
}
ll ans=min(dp[n][],dp[n][]);
if(ans==INF)cout<<"Offline"<<endl;
else {
cout<<"Online"<<endl;
cout<<ans<<endl;
}
return ;
}
URAL 1741 Communication Fiend的更多相关文章
- DP/最短路 URAL 1741 Communication Fiend
题目传送门 /* 题意:程序从1到n版本升级,正版+正版->正版,正版+盗版->盗版,盗版+盗版->盗版 正版+破解版->正版,盗版+破解版->盗版 DP:每种情况考虑一 ...
- Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)
1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...
- URAL 1741 Communication Fiend(最短路径)
Description Kolya has returned from a summer camp and now he's a real communication fiend. He spends ...
- 1741. Communication Fiend(dp)
刷个简单的DP缓缓心情 1A #include <iostream> #include<cstdio> #include<cstring> #include< ...
- URAL DP第一发
列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...
- URAL 1297 Palindrome 后缀数组
D - Palindrome Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- URAL 1297 最长回文子串(后缀数组)
1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...
- Serial Communication Protocol Design Hints And Reference
前面转载的几篇文章详细介绍了UART.RS-232和RS-485的相关内容,可以知道,串口通信的双方在硬件层面需要约定如波特率.数据位.校验位和停止位等属性,才可以正常收发数据.实际项目中使用串口通信 ...
- RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)
前面转载的几篇文章重点介绍了UART及RS-232.在工控领域除了RS-232以外,常用的串行通信还有RS-485.本文转载的文章重点介绍了RS-232.RS-422和RS-485. Overview ...
随机推荐
- Java有序数组的实现
package 有序数组; public class OrdArray { private long[]array; private int nElems; //初始化 public OrdArray ...
- SQL 中单引号 和一些特殊字符的处理
为了防止程序SQL语句错误以及SQL注入,单引号必须经过处理.有2种办法: 1.使用参数,比如SELECT * FROM yourTable WHERE name = @name; 在Java中就是用 ...
- Python3 socketserver模块
socketserver(在Python2.*中的是SocketServer模块)是标准库中一个高级别的模块.用于简化网络客户与服务器的实现(在前面使用socket的过程中,我们先设置了socket的 ...
- EditPlus 4.3.2555 中文版已经发布
新的版本修复了之前版本出现的多行文本缩进调整的问题. 下载连接在页面左上角!
- NOSQL学习之一:Memcached, Redis, MongoDB区别
Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理. Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. MongoDB是一个基于分布 ...
- Python 成对处理数据 zip()
当你想成对处理数据的时候zip() 函数是很有用的.比如,假设你头列表和一个值列表,就像下面这样: headers = ['name', 'shares', 'price'] values = ['A ...
- [转载]C#操作符??和?:
先看如下代码: string strParam = Request.Params["param"]; if ( strParam== null ) { strParam= ...
- linux查看内存free
free 加参数-b/k//m/g,以b.k.m.g的大小显示结果,默认以k显示 [root@oldboy ~]# free total used free shared buffers cached ...
- Nodejs 实现 WebSocket 太容易了吧!!
我们基于express和socket.io开发,首先我们需要安装以下包 npm install --save express npm install --save socket.io 服务器端代码: ...
- 20145118 《Java程序设计》课程总结
20145118 <Java程序设计>课程总结 每周读书笔记连接汇总 假期笔记 http://www.cnblogs.com/cy1123/p/5224305.html 第一周读书笔记 h ...