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): 3443 Accepted Submission (s): 2713
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
Idea: or normal type female function. Note that this topic is not necessarily starting from the credit 1. Be careful when initializing.
#include <stdio.h> #include <string.h>int main () {int T,i,j,k,a,b,n,k,num[10];int c1[45],c2[45],h[45];int MINI;SCANF ("%d", &t), while (t--) {memset (h,0,sizeof (h)); int w=1;mini=100;scanf ("%d%d", &n,&k); for (i=1;i <=k;i++) {scanf ("%d%d", &a,&b); num[a]=b; H[w++]=a; } Memset (C1,0,sizeof (C1)); memset (c2,0,sizeof (C2)); for (i=0;i<=num[h[1]]*h[1];i+=h[1]) //initialization is slightly different from the previous one, with the same intrinsic effect. {c1[i]=1;} for (i=2;i<=k;i++) {for (j=0;j<=n;j++) {for (k=0;k*h[i]+j<=n&&k<=num[h[i]];k++) c2[k*h[i]+j]+=c1 [j];} for (j=0;j<=n;j++) {c1[j]=c2[j];c2[j]=0;}} printf ("%d\n", C1[n]);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2079 Selected Course time (topic has been modified, pay attention to reading questions)