码迷,mamicode.com
首页 > 其他好文 > 详细

ACdream1072——Kill The Monster

时间:2015-05-13 16:54:54      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

题目地址

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x7fffffff;
const int N = 50 + 10;

int dp[N][N][6][6]; /// pos, curTime, cnt, CD
int update[N][N];   /// [time,pos] = mount
int n, m, k, t, b;

vector <pair<int, int> > G[N];
void init() {
    memset(dp, -1, sizeof(dp));
    memset(update, 0, sizeof(update));
    for(int i = 0; i < N; i++) {
        G[i].clear();
    }
}
int dfs(int pos, int time, int cnt, int CD) {
    if(time > t) return 0;

    int& ans = dp[pos][time][cnt][CD];
    if(ans != -1) return ans;

    int adj = update[time][pos], MAX = 0;
    MAX = dfs(pos, time + 1, cnt, max(0, CD - 1));
    for(int i = 0; i < G[pos].size(); i++) {
        int v = G[pos][i].first, w = G[pos][i].second;
        adj += update[time][v];
        MAX = max(MAX, dfs(v, time + w, cnt, max(0, CD - w)));
    }
    ans = MAX + update[time][pos];
    if(cnt >= b || CD != 0) return ans;
    //use skill
    MAX = dfs(pos, time + 1, cnt + 1, 4);
    for(int i = 0; i < G[pos].size(); i++) {
        int v = G[pos][i].first, w = G[pos][i].second;
        MAX = max(MAX, dfs(v, time + w, cnt + 1, max(0, 5 - w)));
    }
    return ans = max(ans, MAX + adj);
}
int main() {
#ifdef TYH
    freopen("in.txt", "r", stdin);
#endif // TYH
    int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%d%d%d%d%d", &n, &m, &t, &k, &b);
        init();
        int u, v, w, x, y, c;
        for(int i = 0; i < m; i++) {
            scanf("%d%d%d", &u, &v, &w);
            G[u].push_back(make_pair(v, w));
            G[v].push_back(make_pair(u, w));
        }
        for(int i = 0; i < k; i++) {
            scanf("%d%d%d", &x, &y, &c);
            update[x][y] += c;
        }
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            ans = max(ans, dfs(i, 1, 0, 0));
        }
        printf("%d\n", ans);
    }
    return 0;
}

ACdream1072——Kill The Monster

标签:

原文地址:http://blog.csdn.net/tyh24689/article/details/45693395

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!