hoj第六届程序设计团体赛 D Game

Game
Time Limit: 1000 MSMemory Limit: 100000 K
Total Submit: 100(25 users)Total Accepted: 35(22 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


本人小白   写的代码  不深奥也不省时      如果有大神可以改进    欢迎评论

#include<stdio.h>
#include<string.h>
int a[20],dp[550];
int max(int a,int b)
{
    if(a>=b)
        return a;
    else
        return b;
}
struct node
{
    int c;
    int v;
} jn[105];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int l,n,m;
        scanf("%d%d%d",&l,&n,&m);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
        }
        a[0]=0,a[n+1]=l;
        for(int i=0; i<m; i++)
        {
            scanf("%d%d",&jn[i].c,&jn[i].v);
        }
        int v,num=0;
        for(int i=1; i<=n+1 ; i++)
        {
            memset(dp,0,sizeof(dp));
            v=a[i]-a[i-1];
            //printf("%d*\n",v);
            for(int j=0; j<m; j++)
            {
                for(int k=jn[j].c; k<=v; k++)
                {
                    dp[k]=max(dp[k],dp[k-jn[j].c]+jn[j].v);
                }
            }
            num+=dp[v];
        }
        printf("%d\n",num);
    }
    return 0;
}

自己写的代码  

写10分钟  dbug  23俩小时

只因为少了一个

memset   

忘记吧dp的 数组清零了     

教训  ;

动规中千万记住吧数组清零了   

否则就是WA



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值