Hrbust 哈理工 oj 2317 Game (完全背包)

Game
Time Limit: 1000 MSMemory Limit: 100000 K
Total Submit: 139(51 users)Total Accepted: 61(45 users)Rating: Special Judge: No
Description

Kim 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 will 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.

  Kim 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 , Kim’s roommate Mik is a Geek(also a Kim fan), he hacked the manager’s computer and get the timetable of the manager, and tell Kim when will the manager come to their room tomorrow. A big E-sport Event is around the corner, so Kim list m skills he should practice, each skill takes some time to practice and improve Kim’s skill by some points. You should calculate the max total improvement points Kim 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 Kim 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, vi, 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 Kim 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 Kim will be catch playing games any time in the interval of his practicing, excluded the beginning and the ending of each practice time. 

Sample 1:

D.Game sample 1

Sample 2:

D.Game sample 2

Source
"科林明伦杯"哈尔滨理工大学第六届程序设计团队赛

完全背包

直接水过。

dp【max】

max是上一次查到下一次查的时间间隔

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct data
{
    int l,e;
}a[100003];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int t,n,m;
        scanf("%d%d%d",&t,&n,&m);
        int v[10003]={0};
        for(int i=0;i<n;i++)
        {
            int a;
            scanf("%d",&a);
            v[a]=1;
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a[i].l,&a[i].e);
        }
        //sort(a,a+m);
        int s=0;
        int dp[10003];
        int ans=0;
        for(int i=1;i<=t;i++)
        {
            if(v[i]||i==t)
            {
               // printf("%d\n",i);
                memset(dp,0,sizeof(dp));
                int l=i-s;
                s=i;
                int z=0;
                for(int j=1;j<=l;j++)
                {
                    for(int k=0;k<m;k++)
                    {
                        if(a[k].l<=j)
                        dp[j]=max(dp[j],dp[j-a[k].l]+a[k].e);
                        z=max(0,dp[j]);
                    }
                }
                ans+=z;
            }
        }
        printf("%d\n",ans);
    }
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值