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. Javascript-逻辑判断或(&&)练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. #C++初学记录(ACM试题1)

    A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...

  3. 百度知道里关于C++的讨论

    1.把C++当成一门新的语言学习(和C没啥关系!真的.): 2.看<Thinking In C++>,不要看<C++变成死相>: 3.看<The C++ Programm ...

  4. LinkedList详解

    一.LinkedList的介绍与特点. 1.继承实现关系. 实现了双端队列接口Deque,因此具有双端队列的功能:addFirt,addLast,offerFirt,offerLast,removeF ...

  5. How To View the HTML Source in Google Chrome

    Whether you are new to the web industry or a seasoned veteran, viewing the HTML source of different ...

  6. activemq 消息队列服务器

    ActiveMQ 安装配置 更多 安装 前置条件:1)安装JDK:2)配置 JAVA_HOME 环境变量,确保 echo $JAVA_HOME 输出JDK的安装路径 下载:wget http://ww ...

  7. Impala shell详解

    不多说,直接上干货! 查看帮助文档 impala-shell -h 刷新整个云数据 impala-shell -ruse impala;show tables; 去格式化,查询大数据量时可以提高性能 ...

  8. ubuntu常用指令

    总结一下常用的linux指令. mark一个linux指令学习和速查的网站:http://man.linuxde.net/ (0) su和sudo:得到root权限 su 切换到root用户 sudo ...

  9. MySQL Crash Course #02# Chapter 3. 4 通配符. 分页

    索引 查看表.文档操作 检索必须知道的两件事 数据演示由谁负责 通配符.非必要不用 检索不同的行 限制结果集.分页查找 运用数据库.表全名 命令后加分号对于很多 DBMS 都不是必要的,但是加了也没有 ...

  10. (三)github之GIT的导入

    什么是版本管理? git是一款[分散型版本管理]软件,提供了开发过程中不可少的功能,例如记录一款软件添加或者更改源代码的过程,回溯到特定阶段,恢复误删除的文件等. 集中型:将仓库集中放在服务器中,一旦 ...