【HDOJ】4109 Instrction Arrangement
差分约束。
/* 4109 */
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
using namespace std; #define MAXV 1005
#define MAXE 41005
#define INF 0x3f typedef struct {
int v, w, next;
} Edge_t; Edge_t E[MAXE];
int head[MAXV], L;
int dis[MAXV];
bool visit[MAXV];
int n, m; void init() {
for (int i=; i<=n; ++i)
dis[i] = INT_MIN;
memset(head, -, sizeof(int)*(n+));
memset(visit, false, sizeof(bool)*(n+));
L = ;
} void addEdge(int u, int v, int w) {
E[L].v = v;
E[L].w = w;
E[L].next = head[u];
head[u] = L++;
} void spfa() {
int i, j, k;
int u, v, w;
queue<int> Q; visit[n] = true;
dis[n] = ;
Q.push(n); while (!Q.empty()) {
u = Q.front();
Q.pop();
visit[u] = false;
for (i=head[u]; i!=-; i=E[i].next) {
v = E[i].v;
w = E[i].w;
if (dis[v] < dis[u]+w) {
dis[v] = dis[u] + w;
if (!visit[v]) {
visit[v] = true;
Q.push(v);
}
}
}
}
} int main() {
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d %d",&n,&m) != EOF) {
init();
while (m--) {
scanf("%d%d%d", &i, &j, &k);
addEdge(j, i, k);
}
for (i=; i<n; ++i)
addEdge(n, i, );
spfa();
k = INT_MIN;
for (i=; i<=n; ++i)
k = max(k, dis[i]);
printf("%d\n", k+);
} return ;
}
【HDOJ】4109 Instrction Arrangement的更多相关文章
- 图论--差分约束--HDU\HDOJ 4109 Instrction Arrangement
Problem Description Ali has taken the Computer Organization and Architecture course this term. He le ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
随机推荐
- 卸载AMH 5.0面板的具体办法
安装AMH 5.0面板只有YES.NO和EXIT,和AMH 4.X的安装.卸载.退出有点不同,那么如何卸载AMH 5.0面板呢? 1.root登录ssh 2.输入如下命令: killall php-f ...
- Linux系统ifconfig命令找不到,centos ifconfig Command not found
centos ifconfig Command not found,Linux系统ifconfig命令找不到 >>>>>>>>>>>& ...
- readonly时禁用删除键,readonly按删除键后页面后退解决方案
readonly时禁用删除键, readonly按删除键后页面后退解决方案 >>>>>>>>>>>>>>>&g ...
- Task类(任务)
任务表示应完成的某个单元的工作.这个单元的工作可以在单独的线程中运行,也可以以同步方式启动一个任务,这需要等待主调用线程.使用任务不仅可以获得一个抽象层,还可以对底层线程进行很多控制. 1.启动任务 ...
- HDU-1015(暴力)
Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is loc ...
- mysql开启函数功能
输入 show variables like '%func%'; 命令 会看到 log_bin_trust_function_creators 的状态,如果是OFF表示自定义函数功能是关闭的 输入命令 ...
- 错误:Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 拒绝访问。
最近,把一个网站部署到另一个服务器上,网站中一个功能word转pdf报下面错误: 在此附上解决方案: 方法1:配置Web.Config文件,在每次请求时模拟本地系统的账户. 具体操作:在Web.Con ...
- error: Unable to find vcvarsall.bat while install python library by pip install or python setup.py install.
Python 2.7 会搜索 Visual Studio 2008. 如果你电脑上没有这个版本的话,比如只有: 1.Visual Studio 2010,在cmd里面执行:SET VS90COMNTO ...
- iOS与Android通用AES加密
找了很久才成功的aes 加密 服务器java写的 下载地址 https://pan.baidu.com/s/1nvi1zjr
- C# 基础 知识点
类型 1.decimal为高精度浮点数,常用于货币计算,然后它不是基本类型,所以性能相对float和double要差. 2.@用于字符串前使转义字符 \ 无效,甚至能将回车当作换行符直接赋值给字符串 ...