博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Exchange Cards(dfs)
阅读量:5748 次
发布时间:2019-06-18

本文共 2301 字,大约阅读时间需要 7 分钟。

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 not always get the money to buy new cards, so sometimes he will exchange with his friends for cards he likes. Of course, different cards have 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 two 5$ cards or three 3$ cards plus one 1$ card, depending on the kinds of cards he have and the number of each kind of card. And Sometimes he will involve unfortunately in a bad condition that he has not got the exact value of the card he is looking for (fans always exchange cards for equivalent value).

Here comes the problem, given the card value he plans to get and the cards he has, Mike wants to fix how many ways he can get it. So it's you task to write a program to figure it out.

Input

The problem consists of multiple test cases, terminated by EOF. There's a blank line between two inputs.

The first line of each test case gives n, the value of the card Mike plans to get and m, the number of different kinds of cards Mike has. n will be an integer number between 1 and 1000. m will be an integer number between 1 and 10.

The next m lines give the information of different kinds of cards Mike have. Each line contains two integers, val and num, representing the value of this kind of card, and the number of this kind of card Mike have.

Note: different kinds of cards will have different value, each val and num will be an integer greater 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 be sure that the output will fall into an integer value.

Output a blank line between two test cases.

Sample Input

5 22 13 110 510 27 25 32 21 5

Sample Output

17 题解:求种类数,i*card.v代表可以加上的价值; 代码:
1 #include
2 struct Node { 3 int v,num; 4 }; 5 Node card[15]; 6 int N,M,tot; 7 void dfs(int x,int now){ 8 if(now==N){ 9 tot++;return;10 }if(now>N||x>=M)return;11 for(int i=0;i<=card[x].num;i++){12 dfs(x+1,now+i*card[x].v);13 }14 }15 int main(){
int flot=0;16 while(~scanf("%d%d",&N,&M)){17 if(flot++)puts("");18 for(int i=0;i

 

转载地址:http://echzx.baihongyu.com/

你可能感兴趣的文章
Django_4_视图
查看>>
Linux的netstat命令使用
查看>>
lvm讲解,磁盘故障小案例
查看>>
大快网站:如何选择正确的hadoop版本
查看>>
经过这5大阶段,你离Java程序员就不远了!
查看>>
IntelliJ IDEA 连接数据库详细过程
查看>>
thymeleaf 学习笔记-基础篇
查看>>
PHP-X开发扩展
查看>>
android学习笔记——onSaveInstanceState的使用
查看>>
工作中如何做好技术积累
查看>>
怎么用sysLinux做U盘双PE+DOS??
查看>>
Spring Transactional
查看>>
shell脚本实例
查看>>
我的友情链接
查看>>
Windows Phone 7 隔离存储空间资源管理器
查看>>
Microsoft Excel 2000/2003修复工具
查看>>
apache安装报错undefined reference ssl
查看>>
关于爱情只有一句忠告
查看>>
CentOS 7下安装部署Oracle11g图文教程
查看>>
F#初学笔记06
查看>>