2317 Game(哈爾濱理工大學)

Game
Time Limit: 1000 MS Memory Limit: 100000 K
Total Submit: 131(45 users) Total Accepted: 56(40 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

思路:簡單的動態規劃。f[i]表示到時間i時最大能獲得多少分數,f[i]=max(f[j]+w[i][j])即枚舉最後一次練習開始的時間,取最大值即可

代碼:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define maxn 1000005
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int dp[501][501],a[10001],b[10001];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        mem(b,0);
        mem(dp,0);
        int l,n,m,v[101],c[101];
        scanf("%d%d%d",&l,&n,&m);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i]-a[i-1];
        }
        b[n]=l-a[n-1];
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&c[i],&v[i]);
        }
        for(int i=0;i<=n;i++)
        {
            //printf("#%d\n",a[i]-a[i-1]);
           for(int j=0;j<=b[i];j++)
           {
               for(int k=0;k<m;k++)
               {
                   if(c[k]>j)
                   {
                       continue;
                   }
                   dp[i][j]=max(dp[i][j],dp[i][j-c[k]]+v[k]);//類似於完全揹包。
                  // printf("@%d\n",dp[i][j]);
               }
           }
        }
        int sum=0;
        for(int i=0;i<=n;i++)
        {
            sum+=dp[i][b[i]];
            //printf("#%d\n",sum);
        }
        printf("%d\n",sum);
    }
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章