差分约束。

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

  1. 图论--差分约束--HDU\HDOJ 4109 Instrction Arrangement

    Problem Description Ali has taken the Computer Organization and Architecture course this term. He le ...

  2. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  3. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  4. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  5. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  6. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  7. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  8. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  9. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

随机推荐

  1. Google Map API v2 步步为营(一) ----- 初见地图

    官方文档:https://developers.google.com/maps/documentation/android/start?hl=zh-CN 先谷歌后百度.使用google的api基本上按 ...

  2. 多目标遗传算法 ------ NSGA-II (部分源码解析) 快速排序代码 sort.c

    /* Routines for randomized recursive quick-sort */ # include <stdio.h> # include <stdlib.h& ...

  3. Java中OutOfMemoryError(内存溢出)的情况及解决办法

    java.lang.OutOfMemoryError: Java heap space // TODO Auto-generated method stub Vector v = new Vector ...

  4. java 内部类学习

    类和内部类的关系就如同人和心脏的关系. 实例1:内部类的基本结构 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 //外部 ...

  5. json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

    注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不 ...

  6. .net下载文件方法

    1.以文件流下载 byte[] fileStr=new byte[5]; MemoryStream btMs = new MemoryStream(fileStr); //以字符流的形式下载文件 by ...

  7. troubleshooting ORA-600[6302] & ORA-600 [6200] corrupted index block

    今天同事的一套数据库遇到了alert 日志 一堆的ora-600,这是一套10.2.0.5 db 2nodes RAC on AIX , 找我帮着看看, 最终确认为一个索引出现了block corru ...

  8. Mybatis的学习总结:mybatis的入门介绍

    一.myBatis简述 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  9. iOS支付总结

    内容大纲: 一.常见的支付方案简介 二.第三方支付SDK 三.苹果官方支付方案 四.Web支付方案 正文: 一.常见的支付方案简介 在微信支付中 微信支付的网址是: https://pay.weixi ...

  10. LINQ 101——分区、Join、聚合

    一.Partitioning 分区 Take 例1:取前3个数 static void Linq1() { , , , , , , , , , }; ); Console.WriteLine(&quo ...