ZOJ - 3017 Extreme Gameplay (floyd + dp + 暴力)

OK, now you've maximized your level and equipments, it seems there is nothing left to pursue in the game Castlevania. But as a steadfast fan of the series you thought it's not enough yet. Since the game keeps a record of the total time spent in completing the game, you decided to minimize it! In Castlevania, of course, you, as a vampire hunter, are trapped in Dracula's castle. There are N chambers in the castle, and since the castle belongs to Lord Alucard, it is not an ordinary castle: in fact it consists of M castles! Fortunately, you, as the heir of the Belmont family, have inherited the knowledge of teleporting freely between these castles in any chamber. For example, you can teleport in chamber X of Castle A to Castle chamber X of Castle B. But it takes a certain amount of magic power to teleport between castles, and you only have Z magic power in total. When the game starts, you are in Chamber 1 and you are to get to chamber N where Alucard himself resides. You start with Z magic and you have to visit each chamber sequentially (first chamber 1 then 2, then 3...finally N). We assume that you are SO good at the game that you would never be beaten by your enemies. And you can only teleport from a castle to another when you have enough magic power.

Input

The first line of the input is T (T <= 10), the number of test cases, then N blocks followed, each with the following form: The first line contains three integers N (N <= 100), M (M <= 10) and Z (Z <= 100), Then M lines followed each containing N - 1 integers. The ith integer of the jth line is the time need to get from chamber i to chamber i + 1 in castle j. Then followed an M * M integer matrix, the jth integer of the ith line is magic power needed to teleport from castle i to j. The magic power needed to teleport from A to B may not equal to the magic power needed to teleport from B to A.

Output

Print the minimum time needed to get from chamber 1 to chamber N in a single line. You start in Castle 1, but you can end in any castle as long as you are in chamber N. The maximum total time will be within 1000000000.

Sample Input

1
4 2 10
3 4 9
1 2 6
10 10
10 10

Sample Output

9

题意:

            有M个城堡,每个城堡有N的连续的房间,每次可以消耗魔法在不同城堡的同一编号的房间中瞬移, 

            或者消耗一定的时间走向本城堡的下一个地点,

            求从1号城堡1号房间出发,到达任意第N个房间的最小时间。 

赛后补题

如果前一个房间魔法够瞬移从前面进行转移 因为数据只有100 直接暴力跑0 - 100魔法值

四层for循环一发过(QAQ惊了)可能数据水

写法如果有问题请留言

#include<bits/stdc++.h>
int t, n, m, z;
int w[15][105];
int dis[15][15];
int dp[105][15][105];
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin >> t;
    while(t--) {
        cin >> n >> m >> z;
        for(int i = 1; i <= m; i++)
            for(int j = 2; j <= n; j++)
                cin >> w[i][j];
        for(int i = 1; i <= m; i++)
            for(int j = 1; j <= m; j++)
                cin >> dis[i][j];
        for(int k = 1; k <= m; ++k)
            for(int i = 1; i <= m ; ++i)
                for(int j = 1; j <= m; ++j)
                    if(dis[i][j] > dis[i][k] + dis[k][j])
                        dis[i][j] = dis[i][k] + dis[k][j];
        for(int i = 1; i <= m; i++)
            dis[i][i] = 0;
        memset(dp, 0x3f3f3f, sizeof(dp));
        dp[z][1][1] = 0;
        for(int i = 2; i <= m; i++){
            if(z - dis[1][i] >= 0)
                dp[z - dis[1][i]][i][1] = 0;
        }
        for(int j = 2; j <= n; j++)
            for(int i = 1;i <= m; i++)
                for(int o = 1; o <= m; o++)
                    for(int k = 0; k <= z; k++)
                        if(k - dis[o][i] >= 0)
                            dp[k - dis[o][i]][i][j] = min(dp[k - dis[o][i]][i][j], dp[k][o][j - 1] + w[i][j]);
        int ans = 0x3f3f;
        for(int i = 0; i <= z; i++)
            for(int j = 1; j <= m; j++)
                ans = min(ans, dp[i][j][n]);
        cout << ans << endl;
    }

}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值