URAL 1741

思路:

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的更多相关文章

  1. DP/最短路 URAL 1741 Communication Fiend

    题目传送门 /* 题意:程序从1到n版本升级,正版+正版->正版,正版+盗版->盗版,盗版+盗版->盗版 正版+破解版->正版,盗版+破解版->盗版 DP:每种情况考虑一 ...

  2. Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)

    1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...

  3. URAL 1741 Communication Fiend(最短路径)

    Description Kolya has returned from a summer camp and now he's a real communication fiend. He spends ...

  4. 1741. Communication Fiend(dp)

    刷个简单的DP缓缓心情 1A #include <iostream> #include<cstdio> #include<cstring> #include< ...

  5. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  6. URAL 1297 Palindrome 后缀数组

    D - Palindrome Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  7. URAL 1297 最长回文子串(后缀数组)

    1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...

  8. Serial Communication Protocol Design Hints And Reference

    前面转载的几篇文章详细介绍了UART.RS-232和RS-485的相关内容,可以知道,串口通信的双方在硬件层面需要约定如波特率.数据位.校验位和停止位等属性,才可以正常收发数据.实际项目中使用串口通信 ...

  9. RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)

    前面转载的几篇文章重点介绍了UART及RS-232.在工控领域除了RS-232以外,常用的串行通信还有RS-485.本文转载的文章重点介绍了RS-232.RS-422和RS-485. Overview ...

随机推荐

  1. Summary: Deep Copy vs. Shallow Copy vs. Lazy Copy

    Object copy An object copy is an action in computing where a data object has its attributes copied t ...

  2. sencha touch调试时Please close other application using ADB: Monitor, DDMS, Eclipse

    1.运行——cmd——  netstat -aon|findstr "5037"  2.打开任务管理器,查看所有进程 显示进程pid(文件-查看)--查找pid=7740的结束.

  3. ARM的Trust Zone技术

    ARM的Trust_Zone技术是一个系统的Access Control的架构. 与AXI,AHB,APB其中的secure,supervisor信号相关联. 与ARM core的模式相关连,当ARM ...

  4. REST服务安全-双向认证

    1. 创建服务器密钥,其密钥库为 d:/mykeys/server.ks,注意keypass和storepass保持一致,它们分别代表 密钥密码和密钥库密码,注意 CN=localhost 中,loc ...

  5. za

    http://www.szjs.gov.cn/bsfw/zdyw_1/zfbz/jgcx/

  6. linux基础命令---tmpwatch

    tmpwatch 删除最近一段时间没有访问的文件,时间以小时为单位,节省磁盘空间.tmpwatch递归删除给定时间未被访问的文件.通常,它用于清理用于临时保存空间(如/tmp)的目录.当更改目录时,t ...

  7. 学写网页 #04# w3school

    索引: HTML 输入类型 XHTML HTML5 HTML5 样式指南和代码约定 WHO 成立于 1948 年. 对缩写进行标记能够为浏览器.翻译系统以及搜索引擎提供有用的信息. code 元素不保 ...

  8. SNMP学习笔记之SNMP 原理与实战详解

    原文地址:http://freeloda.blog.51cto.com/2033581/1306743 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法 ...

  9. 如何在 Linux 中将文件编码转换为 UTF-8

    一个文件:vim 文件名.txt输入 :e ++enc=gbk 强制用gbk打开输入 :w ++enc=utf8 转换到utf8保存. 多个文件:for i in *.txt; do iconv -f ...

  10. 使用CloudFlare 的 PKI 工具集 cfssl 来生成 Certificate Authority (CA) 证书和秘钥文件

    要安装kubernetes最新版集群,https://github.com/opsnull/follow-me-install-kubernetes-cluster 这个文档必须要研习一下了. 以下实 ...