HOJ 3200 - No Game School(多个完全背包)

上周小测的ProblemE,也是我小测一塌糊涂的罪魁祸首。不不不,不是题目难,而是我居然写出了自己一个小时都没看出来的Bug。。。导致全盘崩。。。下次一定要好好写,不能乱写。
传送门:http://acm.hit.edu.cn/hojx/showproblem/3200/
3200 - No Game School

Time limit : 2 s Memory limit : 64 mb
Submitted : 21 Accepted : 13
Submit

Problem Description
BGod is a college student who love computer games, but unfortunately his school just published a rule that Games should disappear in the campus , that means nobody can play computer games in school, including the students dormitory. However, the student don’t take it seriously, that’s why the manager of the school gets so angry that he decided to go to the dormitory to punish the students. You should know the manager any punish those students who is playing games at the moment he enter the room, and leave immediately if nobody is playing game in this room.
BGod is a talented game player , in fact, he is the Carry of a famous Gaming club, so he needs time to practice he’s skills . And luckily , BGod’s roommate PY is a Geek(also a BGod fan), he hacked the manager’s computer and get the timetable of the manager, and tell BGod when will the manager come to their room tomorrow. A big E-sport Event is around the corner, so BGod list m skills he should practice, each skill takes some time to practice and improve BGod’s skill by some points. You should calculate the max total improvement points BGod can get. Note any skills can be practiced any times , including 0.
Input
The first line contains a integer T ( T <= 10 ), then T cases follows.
In each case, there are 3 parts of input.

The first part contains 3 integers L, n, m in a single line.Range[0, L] is the time BGod decide to practice , n is the times manager would enter his room, m indicate the total number of the skills.

The second part contains n integers ti(0 <= ti <= L) in a single line, means the manager would enter his room at ti. Note that ti is giving in the increasing order.

The third part has m lines , each line contains two integers ci(ci <= m), vi(vi <= 200), means this skill needs ci minutes to practice and can make vi points improvement.

L <= 500
n <= 10
m <= 100
Output
For each case, you should output the max points BGod can improve.

Sample Input
2
6 1 3
3
2 3
2 4
2 5
6 2 3
2 4
2 3
2 4
2 5
Sample Output
10
15
Hint
Note that BGod will be catch playing games any in the interval of his practicing, excluded the beginning and the ending of each practice time.
Sample 1:
这里写图片描述
Sample 2
这里写图片描述

题目大意就是:大神喜欢玩游戏,导员不给玩游戏。(怎么好像和某校情况相同(逃
然后有神队友助攻,帮他搞定导员来的时间,他只要在导员不来的时候玩游戏就好了。
而且他可以点任何一个技能点,没有次数限制(怎么还猥琐发育。。。
所以是物品是完全的。
那么,每个导员来的前后间隔可以视为一个背包,每个背包视为完全背包。
AC代码如下:

#include <stdio.h>
#include <string.h>
#define maxm 505 
int dp[maxm];
int MAX(int a, int b)
{
    return a > b ? a : b;
}
struct p
{
    int c, v;
} ps[maxm];
int t[20];
int main()
{
    int kase;
    scanf("%d", &kase);
    while(kase--)
    {
        int l, n, m;
        scanf("%d %d %d", &l, &n, &m);
        t[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d", &t[i]);
        }
        t[n+1] = l;
        for(int i = 1; i <= m; i++)
            scanf("%d %d", &ps[i].c, &ps[i].v);

        int point = 0;

        for(int h = 0; h <= n+1; h++)
        {
            int v = t[h+1] - t[h];
            memset(dp, 0, sizeof(dp));
            for(int i = 1; i <= m; i++)
            {
                for(int j = ps[i].c; j <= v; j++)
                {
                    dp[j] = MAX(dp[j], dp[j-ps[i].c] + ps[i].v);
                }
            }
            point = point + dp[v];
        }
        printf("%d\n", point);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值