ACdream1072——Kill The Monster

题目地址

#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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值