UVA 11375 - Matches

Problem E: Matches

We can make digits with matches as shown below:

Given N matches, find the number of different numbers representable using the matches. We shall only make numbers greater than or equal to 0, so no negative signs should be used. For instance, if you have 3 matches, then you can only make the numbers 1 or 7. If you have 4 matches, then you can make the numbers 1, 4, 7 or 11. Note that leading zeros are not allowed (e.g. 001, 042, etc. are illegal). Numbers such as 0, 20, 101 etc. are permitted, though.

Input

Input contains no more than 100 lines. Each line contains one integer N (1 ≤ N ≤ 2000).

Output

For each N, output the number of different (non-negative) numbers representable if you have N matches.

Sample Input

3
4

Sample Output

2
4


Problemsetter: Mak Yan Kei


终于AC了这题,可以睡觉了。。。


dp[j] 记录 恰好 J 根的方法数,最后方法数还得注意很多细节

用java大数


import java.util.*;
import java.math.*;
public class code1 {
	public static void main(String[] args) {
		int maxn=2000;
		BigInteger []dp=new BigInteger[maxn+10];
		for(int i=1;i<=maxn;i++) dp[i]=new BigInteger("0");
		dp[0]=new BigInteger("1");
		int []num=new int[10];
		num[0]=6;num[1]=2;num[2]=5;num[3]=5;num[4]=4;
		num[5]=5;num[6]=6;num[7]=3;num[8]=7;num[9]=6;
		for(int j=0;j<=maxn;j++){
	        for(int i=0;i<10;i++){
	            if(i==0&&j==0) continue;
	            if(j+num[i]<=maxn){
	                dp[j+num[i]]=dp[j+num[i]].add(dp[j]);
	            }
	        }
	    }
	    for(int i=2;i<=maxn;i++) dp[i]=dp[i].add(dp[i-1]);
	    for(int i=6;i<=maxn;i++) dp[i]=dp[i].add(new BigInteger("1"));
		Scanner scan=new Scanner(System.in);
		while(scan.hasNextInt()){
			int n=scan.nextInt();
			System.out.println(dp[n]);
		}
		scan.close();
	}
}





  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 33
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

炒饭君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值