【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 ;
}
上一篇:Windows 下的.NET+ Memcached安装


下一篇:html规范