ural 1013. K-based Numbers. Version 3(动态规划)
2013-09-05 20:44
399 查看
1013. K-based Numbers. Version 3
Let’s consider K-based numbers, containing exactly N digits. We define a number to be valid if its K-based notation doesn’t contain two successive zeros. For example:
1010230 is a valid 7-digit number;
1000198 is not a valid number;
0001235 is not a 7-digit number, it is a 4-digit number.
Given two numbers N and K, you are to calculate an amount of valid K based numbers, containing N digits.
You may assume that 2 ≤ K ≤ 10; N ≥ 2; N + K ≤ 1800.
题意:
思路:和1009、1012一样;这三个题只是更改了数据范围;1012和本题用到了高精度运算;
View Code
Let’s consider K-based numbers, containing exactly N digits. We define a number to be valid if its K-based notation doesn’t contain two successive zeros. For example:
1010230 is a valid 7-digit number;
1000198 is not a valid number;
0001235 is not a 7-digit number, it is a 4-digit number.
Given two numbers N and K, you are to calculate an amount of valid K based numbers, containing N digits.
You may assume that 2 ≤ K ≤ 10; N ≥ 2; N + K ≤ 1800.
Input
The numbers N and K in decimal notation separated by the line break.Output
The result in decimal notation.Sample
input | output |
---|---|
2 10 | 90 |
思路:和1009、1012一样;这三个题只是更改了数据范围;1012和本题用到了高精度运算;
import java.util.Scanner; import java.util.regex.Pattern; import java.lang.Math; import java.math.BigInteger; public class t1 { public static void main(String[] args) { Scanner ks=new Scanner(System.in); BigInteger a,b,c,d,e; a=new BigInteger("0"); b=new BigInteger("0"); c=new BigInteger("1"); d=new BigInteger("0"); e=new BigInteger("0"); int n,k; n=ks.nextInt(); k=ks.nextInt(); int i; for(i=1;i<k;i++) { d=d.add(c);//调出进制数减1; } b=b.add(d); for(i=2;i<=n;i++) { e=b.multiply(c);//保存变量b的值; b=b.add(a);//更新b的值; b=b.multiply(d);//更新b的值 a=e.multiply(c);//跟新a的值; } b=a.add(b); System.out.println(b.toString()); } }
View Code
相关文章推荐
- URAL 1013. K-based Numbers. Version 3
- Ural 1012. K-based Numbers. Version 2 &&1013. K-based Numbers. Version 3 DP+高精度
- URAL 1013. K-based Numbers. Version 3
- ural 1013. K-based Numbers. Version 3
- Ural(Timus) 1013. K-based Numbers. Version 3
- Ural_1013. K-based Numbers. Version 3(dp + 高精度)
- URAL 1012. K-based Numbers. Version 2
- ural 1012K-based Numbers. Version 2 1013. K-based Numbers. Version 3
- ural 1009. K-based Numbers 1012. K-based Numbers. Version 2 1012. K-based Numbers. Version 3
- ural 1012. K-based Numbers. Version 2
- URAL 1013 K-based Numbers. Version 3
- URAL 1013 K-based Numbers. Version 3(矩阵快速幂+大数)
- ural 1013 K-based Numbers. Version 3
- 【DP && 矩阵快速幂 && 快速乘】URAL - 1013 K-based Numbers. Version 3
- ural 1013 K-based Numbers. Version 3(升级版)
- Ural(Timus) 1012. K-based Numbers. Version 2
- 1013. K-based Numbers. Version 2
- Ural 1012. K-based Numbers. Version 2
- ural 1013 K-based Numbers. Version 3
- URAL 1012 K-based Numbers. Version 2