UVa 11375 - Matches (递推 JAVA 高精度)
来源:互联网 发布:淘宝网天猫秋季女装 编辑:程序博客网 时间:2024/05/27 20:18
[Submit] [Go Back] [Status]
Description
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
[Submit] [Go Back] [Status]
题意:
用n根火柴能组成多少个非负数?火柴不必用完
f[i]表示恰好i根火柴能够组成的非负数个数,则在f[i]的基础上再加上数字x,那么就变为了用i+dx[x]根火柴的方案数
对于数字不能有前导零,在状态i=0的时候不能用0,在最后的时候如果i>=6(0需要的火柴数)的时候方案数加上1就行了
需要高精度
import java.util.*;import java.math.*;public class Main { public static void main(String[] args) { int maxn = 2000 + 20; int[] dx = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; BigInteger[] f = new BigInteger[maxn]; BigInteger[] sum = new BigInteger[maxn]; for(int i=1; i<maxn; i++) { f[i] = BigInteger.ZERO; sum[i] = BigInteger.ZERO; } f[0] = BigInteger.ONE; for(int i=0; i<maxn; i++) { for(int j=0; j<10; j++) { if((i!=0 || j!=0) && i + dx[j] < maxn) f[i+dx[j]] = f[i+dx[j]].add(f[i]); } } sum[0] = BigInteger.ZERO; for(int i=1; i<maxn; i++) sum[i] = sum[i-1].add(f[i]); Scanner in = new Scanner(System.in); while(in.hasNextInt()) { int n = in.nextInt(); if(n < 6) System.out.println(sum[n]); else System.out.println(sum[n].add(BigInteger.ONE)); } }}
- UVa 11375 - Matches (递推 JAVA 高精度)
- Uva 11375 Matches 解题报告(递推+高精度)
- 动态规划,递推,高精度(Matches,uva 11375)
- uva 11375 Matches 递推关系||DP||高精度
- UVA 11375 Matches——递推+高精度
- UVA 11375 Matches(递推)
- uva 11375 - Matches(递推)
- UVA 11375 Matches (dp+高精度)【模板】
- UVa 11375 Matches (DP&高精度)
- UVA - 11375-Matches-dp+高精度
- UVA 11375 - Matches (数学——递推)
- uva 1647 高精度+递推
- Matches(uva 11375)
- [高精度+递推] uva 10328 Coin Toss
- UVA 10328 Coin Toss【带限制条件的递推dp+计数技巧+高精度用java】
- poj2506(递推+高精度)
- Poj 2506 Tiling (Java高精度 + 递推)
- JAVA高精度4_递推求值
- 程序运行地址和加载地址-为什么使用位置无关指令
- SQL 2008根据条件拆分列
- 只是个人笔记
- UVA - 442 Matrix Chain Multiplication
- spring2.5 mvc 以及spring3.0 mvc ajax+json
- UVa 11375 - Matches (递推 JAVA 高精度)
- 二分查找 java
- 【学生信息管理系统】总结--这只是个开始
- C语言1关键字与符号
- linux下svn无法提交,svn ci无任何反映的问题
- 网络命令一览表
- Linux下C++程序常用编译命令
- Java线程(六):线程池
- Response.Redirect与Server.Transfer区别