nyoj90 整数划分
来源:互联网 发布:js判断网址是否变化 编辑:程序博客网 时间:2024/06/11 13:37
整数划分
时间限制:3000 ms | 内存限制:65535 KB
难度:3
- 描述
- 将正整数n表示成一系列正整数之和:n=n1+n2+…+nk,
其中n1≥n2≥…≥nk≥1,k≥1。
正整数n的这种表示称为正整数n的划分。求正整数n的不
同划分个数。
例如正整数6有如下11种不同的划分:
6;
5+1;
4+2,4+1+1;
3+3,3+2+1,3+1+1+1;
2+2+2,2+2+1+1,2+1+1+1+1;
1+1+1+1+1+1。- 输入
- 第一行是测试数据的数目M(1<=M<=10)。以下每行均包含一个整数n(1<=n<=10)。
- 输出
- 输出每组测试数据有多少种分法。
- 样例输入
16
- 样例输出
11
package nyoj90;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.Scanner;public class Main {public static List<List<Integer>> consum(int[] candidate, int sum){List<List<Integer>> result = new ArrayList<List<Integer>>();Arrays.sort(candidate);ArrayList<Integer> list = new ArrayList<Integer>();compute(candidate, 0, sum, 0, list, result);return result;}private static void compute(int[] candidate, int start, int sum, int cur, List<Integer> list, List<List<Integer>> result){if(cur>sum)return;if(cur==sum){result.add(list);return;}for(int i=start;i<candidate.length;i++){List<Integer> temp = new ArrayList<Integer>(list);temp.add(candidate[i]);compute(candidate, i, sum, cur+candidate[i], temp, result);}}public static void main(String[] args) {Scanner reader = new Scanner(System.in);int N = reader.nextInt();while(N-->0){int n = reader.nextInt();int[] candidate = new int[n];for(int i=0;i<n;i++){candidate[i] = i+1;}List<List<Integer>> reault = consum(candidate, n);System.out.println(reault.size());}reader.close();}}
0 0
- nyoj90 整数划分
- NYOJ90 整数划分 【深搜】
- NYOJ90-整数划分
- NYOJ90整数划分
- nyoj90整数划分
- nyoj90 整数划分
- NYOJ90整数划分
- nyoj90整数划分(dp)
- NYOJ90-整数划分,经典递归思想~~
- NYOJ90 整数划分(经典递归和dp)
- nyoj90
- nyoj90 整数拆分(递归,背包两种解法)
- 整数划分
- 整数划分
- 整数划分
- 整数划分
- 整数划分
- 整数划分
- 近期动态
- 传输层
- 欢迎使用CSDN-markdown编辑器
- 双向循环链表-解决顺逆时针约瑟夫环
- 两种扇形束CT投影生成方法
- nyoj90 整数划分
- 用GDB调试程序(一)
- http://www.cnblogs.com/yezhenhan/archive/2012/01/07/2315652.html
- PE-FILE
- 理解:String与StringBuffer的区别
- CSS生成字体@font-face
- 用GDB调试程序(二)
- 通过分析SQL语句的执行计划优化SQL(总结)
- hpuoj 1248: HH的军训 (容斥原理)