hrboj-【2317 Game】

来源:互联网 发布:算法的概念数学 编辑:程序博客网 时间:2024/05/16 18:32
GameTime Limit: 1000 MSMemory Limit: 100000 KTotal Submit: 72(21 users)Total Accepted: 24(15 users)Rating: Special Judge: NoDescription

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
26 1 332 32 42 56 2 32 42 32 42 5
Sample Output
1015
完全背包问题,很简单,我当成01背包了,唉最讨厌dp了,是时候学学了
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int get_max(int a,int b){if(a>b)return a;return b; } struct node{int wi;int pi;}arr[1500];int w[1100],f[1100];int ff[20]; int main(){int t;scanf("%d",&t);while(t--){int l,n,m,i,temp=0,k;scanf("%d%d%d",&l,&n,&m);for(i=0;i<n;++i)scanf("%d",&ff[i]);sort(ff,ff+n);for(i=0;i<n;++i){w[i]=ff[i]-temp;temp=ff[i]; } w[i]=l-ff[i-1];int j,g;for(j=1;j<=m;++j)scanf("%d%d",&arr[j].wi,&arr[j].pi);int ans=0; for(k=0;k<=i;++k){int sum=w[k];memset(f,0,sizeof(f)); for(j=1;j<=sum;++j){for(g=1;g<=m;++g){if(arr[g].wi>j)continue;f[j]=get_max(f[j],f[j-arr[g].wi]+arr[g].pi); } } ans+=f[sum]; }printf("%d\n",ans); } return 0;} 


0 0
原创粉丝点击