BUPT 199 Beat it!

本文解析了一个名为BUPT199Beatit!的游戏中的算法问题,该游戏背景设定在一个奇异国度中,玩家需要利用一种特殊的大炮攻击怪物。文章详细介绍了如何通过动态规划的方法来计算在特定条件下对怪物造成的最大伤害值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BUPT 199 Beat it!

Description

There's a monster-attacking game on the Renren's open platform, and the game's background are showing below.

Where lies a strange country, lices a strange monster. The strange people in that strange country are persecuted by the strange monster. So teh strange people make a strange cannon to defeat the strange monster.

As far as we know, the strange cannon is powerful, but once it works, it should not work in next T hours (Eg. If it fired at time 1, then time 2 to time T it cannot work). When the strange monster get hit during the daylight, it get PD point hurt; it will get PN point hurt when it happens during the night. As the country is strange, the time of the daylight and night changes eveyday. In the ith day, the daylight starts at time 1 and ends at time T1[i], then from time (T1[i]+1) to time (T1[i]+T2[i]) is night.

Here comes a question: what is the maximal hurt point would the strange monster got after N days?



Input

First line contains an integer Q (1<=Q<=20), indicates the number of test cases.

For each case, first line contains 4 integers: N (1<=N<=1000), T (1<=T<=100), PD, PN.

Then followed N lines, the (i+1)th line contains 2 integer T1[i], T2[i].

(PD, PN, T1[i], T2[i] are all non-negative and fit the 32bit integer)



Output

For each case print one line, output the answer. See the sample for format.


Sample Input


1

2 5 20 5

6 10

2 1



Sample Output

Case 1: 65


#include <stdio.h>
#include <stdlib.h>

int Q;
long long N, T, PD, PN;
long long t1[1001], t2[1001];
long long f[201];

int main(){
		int i, j, k, i1, i2, i3;
		long long extra, t;
		scanf("%d", &Q);
		for (k = 1; k <= Q; k++){
			scanf("%lld%lld%lld%lld", &N, &T, &PD, &PN);
			extra = 0;
			for (i = 0; i < N; i++){
				scanf("%lld%lld", &t1[i], &t2[i]);
				if (t1[i] > 300){
					t = t1[i] - 300;
					t -= (t % T);
					extra += t / T * PD;
					t1[i] -= t;
				}
				if (t2[i] > 300){
					t = t2[i] - 300;
					t -= (t % T);
					extra += t / T * PN;
					t2[i] -= t;
				}
			}
			f[0] = 0;
			for (i = 1, j = 0; j < N; j++){
				for (t = 1; t <= t1[j]; t++){
					i1 = i % 200;
					i2 = (i - 1) % 200;
					i3 = (i - T) % 200;
					
					f[i1] = f[i2];
					if (i <= T) f[i] = PD;
					else{
						if (f[i1] < f[i3] + PD)
							f[i1] = f[i3] + PD;
					}
					i++;
				}
				for (t = 1; t <= t2[j]; t++){
					i1 = i % 200;
					i2 = (i - 1) % 200;
					i3 = (i - T) % 200;

					f[i1] = f[i2];
					if (i <= T) f[i] = PN;
					else{
						if (f[i1] < f[i3] + PN)
							f[i1] = f[i3] + PN;
					}
					i++;
				}
			}
			printf("Case %d: %lld\n", k, extra + f[(i - 1) % 200]);
		}
	system("pause");
	return 0;
}

/**********************

容易想到

f[i] 第i段时间得到最大伤害

f[i] = max{f[i - T] + val, f[i - 1]}

但显然会超时。想到青蛙过河的题,长度很长时,中间一段是可以缩的,

于是猜了个数300, 大于它的都可开炮。

场上WA了5次,不明真相,下来后发现是初始化写在循环外面了,我去...

第6次,无奈,改了状态

f[i][j] 第i个半天,剩余冷却时间为j时,最大伤害

一次A过...

**********************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值