//将n 分成k份的 分法总数 #include "stdafx.h" #include"stdio.h" #include<iostream> using namespace std; int f(int n,int k) { if (k == 2) return n / 2; else { int s = 0; for (int i = 1; i <= n / k; i++)//第一份初始值i s = s + f(n - (i - 1)*k -
Description You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q. For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to th
[程序21] 题目:求1+2!+3!+...+20!的和 1.程序分析:此程序只是把累加变成了累乘. public class Ex21 { static long sum = 0; static long fac = 0; public static void main(String[] args) { long sum = 0; long fac = 1; for(int i=1; i<=10; i++) { fac = fac * i; s
JAVA经典算法40题 [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... public class exp2{ public static void main(String args[]){ int i=0; for(i=1;i<=20;i++) System.out.println(f(i)); }