zoj 2734
来源:互联网 发布:2016年网络用语 编辑:程序博客网 时间:2024/05/22 10:08
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
Author: DAI, Wenbin
Source: Zhejiang University Local Contest 2006
#include<iostream>#include<algorithm>#include<memory.h>using namespace std;int card[100];int n,m;int sum;int ways;void DFS(int x){if(sum == n){ways++;return;}for(int i=x; i<=n; i++){if( card[i] && sum + i<=n){sum += i;card[i]--;DFS(i);card[i]++;sum -= i;}}}int main(){int p = 0;while(cin>>n>>m){if(p)cout<<endl;p = 1;memset(card, 0, sizeof(card));sum = 0;ways = 0;int val,num;while(m--){cin>>val>>num;card[val] = num;}DFS(1);cout<<ways<<endl;} return 0;}
- zoj 2734
- ZOJ-2734
- ZOJ 2734 Exchange Cards
- zoj - 2734 - Exchange Cards
- zoj 2734 Exchange Cards
- zoj 2734 Exchange Cards
- zoj 2734 Exchange Cards
- zoj 2734 Exchange Cards
- zoj Exchange Cards 2734
- ZOJ 2734(Exchange Cards)
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- Java HttpURLConnection 联网超时问题
- Oracle的优化器的优化方式
- C# 委托的使用
- 解决serv-u乱码
- 创建 Web Services
- zoj 2734
- oracle hint (体系)了解
- C# 实现对XML文件的基本操作(创建xml文件,增、删、改、查 xml节点信息)
- 单词
- MUF学习一框架概述
- MATLAB 绘图基础
- 在tomcat6下配置log4j 日志
- 汽车-前轮鼓包
- 数据库的几个范式(一二三)