UVA10198 Counting大数+递推
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10198 Counting大数+递推相关的知识,希望对你有一定的参考价值。
Gustavo knows how to count, but he is now learning how write numbers. As he is a very good student, he already learned 1, 2, 3 and 4. But he didn’t realize yet that 4 is different than 1, so he thinks that 4 is another way to write 1. Besides that, he is having fun with a little game he created himself: he make numbers (with those four digits) and sum their values. For instance:
132 = 1 + 3 + 2 = 6
112314 = 1 + 1 + 2 + 3 + 1 + 1 = 9 (remember that Gustavo thinks that 4 = 1)
After making a lot of numbers in this way, Gustavo now wants to know how much numbers he can create such that their sum is a number n. For instance, for n = 2 he noticed that he can make 5 numbers: 11, 14, 41, 44 and 2 (he knows how to count them up, but he doesn’t know how to write five). However, he can’t figure it out for n greater than 2. So, he asked you to help him.
Input
Input will consist on an arbitrary number of sets. Each set will consist on an integer n such that 1 ≤ n ≤ 1000. You must read until you reach the end of file.
Output
For each number read, you must output another number (on a line alone) stating how much numbers Gustavo can make such that the sum of their digits is equal to the given number.
Sample Input
2
3
Sample Output
5
13
问题链接:UVA10198 Counting
问题简述:(略)
问题分析:大数递推问题,用Java语言来解决。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的Java语言程序如下:
/* UVA10198 Counting */
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int N = 1000;
BigInteger f[] = new BigInteger[N + 1];
Arrays.fill(f, BigInteger.ZERO);
f[0] = BigInteger.valueOf(1);
f[1] = BigInteger.valueOf(2);
f[2] = BigInteger.valueOf(5);
f[3] = BigInteger.valueOf(13);
for(int i = 4; i <= N; i++)
f[i] = f[i].add(f[i-1]).add(f[i-1]).add(f[i-2]).add(f[i-3]);
int n;
while(input.hasNextInt()){
n = input.nextInt();
System.out.println(f[n]);
}
}
}
以上是关于UVA10198 Counting大数+递推的主要内容,如果未能解决你的问题,请参考以下文章