【HDOJ】1224 Free DIY Tour
DP。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std; #define MAXN 105
int score[MAXN];
bool map[MAXN][MAXN];
int path[MAXN];
int dp[MAXN]; void print_path(int x) {
if (path[x] != )
print_path(path[x]);
printf("%d->", x);
} int main() {
int t, n, m;
int i, j, k, tmp; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
for (k=; k<=t; ++k) {
scanf("%d", &n);
for (i=; i<=n; ++i)
scanf("%d", &score[i]);
score[n+] = ;
memset(map, false, sizeof(map));
memset(dp, , sizeof(dp));
memset(path, , sizeof(path));
scanf("%d", &m);
while (m--) {
scanf("%d %d", &i, &j);
map[i][j] = true;
}
for (i=; i<=n+; ++i) {
int max = , v = ;
for (j=; j<i; ++j) {
if (map[j][i] && dp[j] >= max) {
max = dp[j];
v = j;
}
}
dp[i] = max + score[i];
path[i] = v;
}
printf("CASE %d#\n", k);
printf("points : %d\n", dp[n+]);
printf("circuit : ");
print_path(path[n+]);
printf("1\n");
if (k != t)
printf("\n");
} return ;
}
【HDOJ】1224 Free DIY Tour的更多相关文章
- HDU 1224 Free DIY Tour(spfa求最长路+路径输出)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1224 Free DIY Tour Time Limit: 2000/1000 MS (Java/Oth ...
- HDU ACM 1224 Free DIY Tour (SPFA)
Free DIY Tour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 【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.假设我们现在知 ...
随机推荐
- 技能CDDemo(点击鼠标左键实现技能界面旋转)
using UnityEngine; using System.Collections; using UnityEngine.UI; public class HealthController : M ...
- 【mac开发.NET】No installed provisioning profiles match the installed iOS signing identities
编译错误提示 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets: Er ...
- UIKit和Core Graphics绘图(一)——字符串,线条,矩形,渐变
概述 CoreGraphics也称为Quartz 2D 是UIKit下的主要绘图系统,频繁的用于绘制自定义视图.Core Graphics是高度集成于UIView和其他UIKit部分的.Core Gr ...
- Windows7 64位系统搭建Cocos2d-x 2.2.1最新版以及Android交叉编译环境(具体教程)
原文地址:http://blog.csdn.net/sttyytw/article/details/17005263 声明:本教程在參考了下面博文,并经过自己的摸索后实际操作得出,本教程系本人原创,因 ...
- [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State
ngrx/store is a library that simplifies common RxJS patterns for managing state and gives you an eas ...
- Thinkpad Edge E440 Ubuntu14.04 无线网卡驱动 解决
http://ubuntuforums.org/showthread.php?t=2190347 正文: Thinkpad Edge E440 安装 Ubuntu12.04 后 无法使用无线网卡, 须 ...
- Jetty开发指导:框架
Spring设置 你能嵌入Jetty到你的项目中,也能够使用差点儿全部的IoC类型框架,包含Spring.假设全部你想做的是在你的Spring中设置Jetty Server,那么以下的xml片段能够作 ...
- wildcard
[rusky@rhel7 test]$ lstest1 test123 test2 test317 test33 test335 test336 test44 testtest[rus ...
- linux定时任务1-crontab命令
简单测试例子: 添加定时任务前,注意查看crond服务是否已经启动,如果未启动,则用命令service crond start命令启动. 注意给脚本添加可执行权限. [root@rheltest1 ~ ...
- C# Byte[]数组读取和写入文件
这个项目我用的是asp.net构建的,代码如下 protected void ByteToString_Click(object sender, EventArgs e) { string conte ...