Exchange Cards Time limit: 2 Seconds Memory Limit: 65536 KB
As a basketball fan, Mike is also fond of collecting basketball player cards. But as a student, he can don't always get the money to buy new cards, so sometimes he'll exchange with his friends for car DS He likes. Of course, different cards has different value, and Mike must use cards he owns to get the new one. For example, to-get a card of value 10$, he can use both 5$ cards or three 3$ cards plus one 1$ card, depending on the kind S of cards He has and the number of each kind of card. And sometimes he'll involve unfortunately in a bad condition that he had not got the exact value of the card he's Looki Ng for (fans All Exchange cards for equivalent value).
Here comes the problem, given the card value he plans to get and the cards he have, Mike wants to fix how many ways he can Get it. So it's a task to the write a program to figure it out.
Input
The problem consists of multiple test cases, terminated by EOF. There ' s a blank line between and inputs.
The first line of all test case gives n, the value of the card Mike plans to get and m, the number of D Ifferent kinds of Cards Mike has. n would be is an integer number between 1 and 1000. m 'll be is an integer number between 1 and 10.
The next m lines give the information of different kinds of cards of Mike have. Each line contains-integers, val and Num, representing the value of this kind of card, and the Numbe R of this kind of card Mike has.
Note: different kinds of cards'll has different value, each val and num would be a integer g Reater than zero.
Output
For each test case, output in one line the number of different ways Mike could exchange for the card he wants. You can is sure that the output would fall into an integer value.
Output a blank line between the test cases.
Sample Input
5 22 13 110 510 27 25 32 21 5
Sample Output
17
I*CARD.V: The number of categories, the value that the representative can add;
Code:
1#include <stdio.h>2 structNode {3 intV,num;4 };5Node card[ the];6 intN,m,tot;7 voidDfsintXintNow ) {8 if(now==o) {9tot++;return;Ten}if(now>n| | X>=M)return; One for(intI=0; i<=card[x].num;i++){ ADFS (x+1, now+i*card[x].v); - } - } the intMain () {intflot=0; - while(~SCANF ("%d%d",&n,&M)) { - if(flot++) puts (""); - for(intI=0; i<m;i++) scanf ("%d%d",&card[i].v,&card[i].num); +tot=0; -Dfs0,0); +printf"%d\n", tot); A } at return 0; -}
Exchange Cards (DFS)