UVA 11375
来源:互联网 发布:杭州知奥贸易有限公司 编辑:程序博客网 时间:2024/06/06 15:39
11375 - Matches
Time limit: 2.000 seconds
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
34
Sample Output
24
Problemsetter: Mak Yan Kei本题是递推,给你n根火柴问你能组成多少个非负整数。用c数组记录每个数字需要的火柴数。dp记录用i根火柴可以组成的正整数。dp数组可递推出。注意n >=6时要加一,代表整数0.
import java.math.BigInteger;import java.util.Scanner;public class Main{ public static void main(String[] args){final BigInteger ONE = new BigInteger("1");final int[] c = {6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6};final int N = 2150;BigInteger dp[] = new BigInteger[N];for(int i = 1 ; i < N ; i++)dp[i] = new BigInteger("0");dp[0] = ONE;for(int i = 0 ; i <= 2100 ; i++){for(int j = 0 ; j < 10 ; j++){ if(!(i == 0&&j == 0) )dp[i + c[j]] = dp[i + c[j]].add(dp[i]);}if(i > 0)dp[i] = dp[i].add(dp[i - 1]);}for(int i = 0 ; i < 6 ; i++){dp[i] = dp[i].subtract(ONE);}Scanner cin = new Scanner(System.in);while(cin.hasNext()){int n = cin.nextInt();System.out.println(dp[n]);} }}
- UVA 11375
- uva 11375
- Matches UVA 11375
- uva 11375 - Matches
- UVA 11375 - Matches
- UVA 11375 Mathes
- UVA 11375 - Matches
- UVA - 11375 Matches
- UVa:11375 Matches
- uva 11375 递推
- UVa 11375 Matches
- UVa 11375 Matches
- Matches(uva 11375)
- uva
- UVA
- UVA
- UVA
- uva
- 再次写给我们这些浮躁的程序员
- 三个值得关注的开源UTM产品
- Android瀑布流照片墙实现
- oracle中使用append的问题
- Drupal 7 导入翻译时出错的解决方法
- UVA 11375
- 程序员面试智力题(三)
- pthread_cond_wait()用法分析
- linux 压缩、解压缩
- 程序员面试智力题(四)
- mysql密码修改
- [黑客入门全程图解].吴自容,武新华.等编著.文字版,精确还原
- NoSQL开篇——为什么要使用NoSQL
- 关于电信路由猫、无线路由猫的设置