Course selection time (subject has been modified, pay attention to reading questions)Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 3250 Accepted Submission (s): 2551
Problem description again to the time to choose class, Xhd looked at the timetable, in order to make the next semester better, he wants to know how many combinations of n credits. You can help him. (Xhd think the same credit class is no different)
The first line of input data is a data T, which indicates that there is a T group of data.
The first line of data for each group is two integers n (1 <= n <=), K (1 <= k <= 8).
Then there are k lines, each line has two integers a (1 <= a <= 8), B (1 <= b <= 10), the class that divides into a has B gate.
Output for each set of input data, outputs an integer that represents the number of combinations of n credits.
Sample Input
22 21 22 140 81 12 23 24 25 86 97 68 8
Sample Output
2445
Authorxhd
SOURCEACM Programming Final Exam-warm-up (Thanks XHD & 8600)
#include <stdio.h> #include <string.h>int c1[110],c2[110];int arr[20];int main () {int s;int a,b;int n,k,i,j, L;SCANF ("%d", &s), while (s--) {scanf ("%d%d", &n,&k); Memset (C1,0,sizeof (C1)); memset (c2,0,sizeof (C2)); for (i=0;i<k;i++) {scanf ("%d%d", &a,&b); arr[a]=b;} for (i=0;i<=arr[1];i++) c1[i]=1;for (i=2;i<=8;i++) {for (j=0;j<=40;j++) {for (k=0,l=0;l<=arr[i]&& k+j<=40;k+=i,l++) c2[k+j]+=c1[j];} for (j=0;j<=40;j++) {c1[j]=c2[j];c2[j]=0;}} printf ("%d\n", C1[n]);} return 0;}
HDU 2079 selected class time (title modified, attention to reading) "Mother function"