【简单dp】Boxes of Chocolates Again

来源:互联网 发布:阿德昆托博生涯数据 编辑:程序博客网 时间:2024/05/29 17:06
//http://www.bnuoj.com/bnuoj/contest_show.php?cid=5763#problem/65363
//题意给一个整数,问有多少种组合方式(如3=1+1+1=1+2=3,所以3有3种组合方式)
//生活艰辛。。。被自己蠢哭了<img alt="再见" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/bye.gif" />
import java.util.*;import java.math.*;public class Main {public static void main(String args[]) {final int MAX = 5001;BigInteger [] dp = new BigInteger[MAX];for (int i = 0; i < MAX; ++i) {dp[i] = new BigInteger("0");}dp[0] = BigInteger.ONE;for (int j = 1; j < MAX; ++j) {for (int i = j; i < MAX; ++i) {dp[i] = dp[i].add(dp[i-j]);}}int n;Scanner cin = new Scanner(System.in);while (cin.hasNextInt()) {n = cin.nextInt();System.out.println(dp[n]);}}}
0 0
原创粉丝点击