33,008
社区成员
发帖
与我相关
我的任务
分享
public class Test {
/**
* 可取的数量
*/
private static int MAX_LEN = 10;
/**
* 可选择的最大值
*/
private static int MAX_VALUE = 200;
/**
* 预期值
*/
private static int VALUE = 1024;
/**
* 结果
*/
private static long RESULT;
/**
* 储存结果、验证
*/
//private static int[] results = new int[MAX_LEN];
public static void main(String[] args) {
next(0, 0);
System.out.println(RESULT);
}
public static void next(int sum, int currentLen){
if (currentLen + 1 == MAX_LEN) {
if (VALUE - sum > 100) {
RESULT++;
//results[currentLen] = VALUE - sum;
//print();
}
return;
}
for (int i = 100; i < MAX_VALUE; i++) {
//results[currentLen] = i;
long currentResult = RESULT;
next(sum + i, currentLen + 1);
if (currentResult == RESULT) {
return;
}
}
}
/* private static void print(){
for (int result : results) {
System.out.print(result + " ");
}
System.out.println();
}*/
}
public class Test {
public int min, max, sum, num;
public long[][] dp;
public Test() {
min = 0;
max = 24;
sum = 24;
num = 10;
// min = 100;
// max = 200;
// sum = 1024;
// num = 10;
dp = new long[num + 1][sum + 1];
for (int i = 0; i <= num; ++i) {
Arrays.fill(dp[i], 0);
}
long ans = solution(num, sum);
System.out.println(ans);
}
private long solution( int N,
int S) {
if (0 == N) {
if (0 == S) {
return 1;
}
return 0;
}
if (S < min * N || S > max * N) {
return 0;
}
if (dp[N][S] > 0) {
return dp[N][S];
}
long count = 0;
for (int i = min; i <= max; ++i) {
count += solution(N - 1, S - i);
}
dp[N][S] = count;
return count;
}
public static void main(String[] args) {
new Test();
}
}