HDU 2079-course selection time (primary function), hdu2079-Course Selection Function
Course Selection time (the question has been modified. Read the question)Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 2996 Accepted Submission (s): 2347
The time for selecting the course is now when Problem Description comes. xhd looks at the course selection table in a daze. To make the next semester better, he wants to know the total number of combinations of n credits. You can help him. (Xhd believes that the same credit course is no different)
The first line of Input data is a data T, indicating that T groups of data exist.
The first row of each data group is two integers, n (1 <= n <= 40) and k (1 <= k <= 8 ).
Then there are k rows. Each row has two integers a (1 <= a <= 8), B (1 <= B <= 10 ), there are B Courses for which credits are.
Output outputs an integer for each group of input data, indicating the number of groups of n credits.
Sample Input
22 21 22 140 81 12 23 24 25 86 97 68 8
Sample Output
2445 .. Sleep ~#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>#include <list>#define maxn 250#define ll long long#define INF 0x3f3f3f3f#define pp pair<int,int>using namespace std;int a[maxn],b[maxn],v[10],p,num[10],n;void solve(){memset(a,0,sizeof(a));a[0]=1;for(int i=0;i<n;i++){memset(b,0,sizeof(b));for(int j=0;j<=num[i]&&j*v[i]<=p;j++)for(int k=0;k+j*v[i]<=p;k++)b[k+j*v[i]]+=a[k];memcpy(a,b,sizeof(b));}printf("%d\n",a[p]);}int main(){int T;scanf("%d",&T);while(T--){scanf("%d%d",&p,&n);for(int i=0;i<n;i++)scanf("%d%d",&v[i],&num[i]);solve();}return 0;}