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): 1516 accepted submission (s): 1253
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 input2 2 2 1 2 1 40 8 1 1 2 2 2 2 2 4 2 5 8 6 9 7 6 8 8
Sample output2 445
Authorxhd
Sourceacm Program Design final exam _ warm-up (thanks to xhd & 8600)
Recommendlcy
1 #include<stdio.h> 2 #include<string.h> 3 #define MAXN 40 4 int a[10],b[10]; 5 int c1[MAXN+10],c2[MAXN+10]; 6 int n; 7 void mufun(int k) 8 { 9 memset(c1,0,sizeof(c1));10 memset(c2,0,sizeof(c2));11 for(int i=0;i<=b[0]&&i*a[0]<=n;i++)12 c1[i*a[0]]=1;13 for(int t=1;t<k;t++)14 {15 for(int i=0;i<=n;i++)16 {17 for(int j=0;j+i<=n&&j/a[t]<=b[t];j+=a[t])18 c2[i+j]+=c1[i];19 20 } 21 for(int i=0;i<=n;i++)22 {23 c1[i]=c2[i];24 c2[i]=0;25 } 26 } 27 } 28 int main()29 {30 int T;31 scanf("%d",&T);32 int k;33 while(T--)34 {35 scanf("%d%d",&n,&k);36 for(int i=0;i<k;i++)37 scanf("%d%d",&a[i],&b[i]);38 mufun(k);39 printf("%d\n",c1[n]);40 } 41 return 0;42 }View code
Course Selection time!