14个数 某几个数的和是一个固定值 求算法!(在线等) 14个数 某几个数的和是一个固定值 求算法!(在线等) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.FileWriter;import java.io.PrintWriter;import java.util.ArrayList;import java.util.Collections;import java.util.List;public class NumberDemo { public final static int[] a = new int[] { 3972, 6294, 994, 976, 3420, 1946, 7962, 1016, 6770, 3196, 7408, 1128, 1016, 1898 }; private static int sum1 = 35054; private static int sum2 = 12942; private static int total = 14; private static int[] coff = new int[total]; private static List list = new ArrayList(); private static void copy(int[] a, int[] b) { for (int i = 0; i < a.length; i++) { a[i] = b[i]; } } public static void Package(int index) { if (index == total) { int s = getSum(coff); if(s== sum1) { show(sum1, coff); } if (s == sum2) { show(sum2, coff); } return; } for (int i = 0; i < 2; i++) { coff[index] = i; Package(index + 1); } } public static void main(String[] args)throws Exception { Package(0); PrintWriter out = new PrintWriter(new FileWriter("c:/1.txt")); Collections.sort( list); for(int i=0;i<list.size();i++){ out.println(list.get(i)); } out.flush() ; out.close(); } public static void show(int s, int[] coff) { System.out.print(s + ":"); for (int i = 0; i < coff.length; i++) { System.out.print(coff[i] * a[i] + " "); } System.out.println(); } public static int getSum(int[] coff) { int res = 0; for (int i = 0; i < coff.length; i++) { res += coff[i] * a[i]; } list.add(new Integer(res)); return res; }} hibernate 3.5.3 需要引入那些包? 关于模态对话框的问题 高分!!!跪求简单的javabean封装小问题 大哥大姐门帮帮我! 为什么在使用标签库的JSP文件中引入JAVABEAN会出错(有错误提示) 两个tomcat上jsp怎样传参数 jsp中如何对含有中文的url进行编码 怎样处理jsp+mysql查询结果中的乱码问题. 新年散分-WEB开发中用户权限和翻页问题讨论 ewr jsp中调用flash问题 帮忙啊! 在编译一个javabean时无法import另一个已编译好javabean?求教高手
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;public class NumberDemo {
public final static int[] a = new int[] { 3972, 6294, 994, 976, 3420, 1946,
7962, 1016, 6770, 3196, 7408, 1128, 1016, 1898 }; private static int sum1 = 35054; private static int sum2 = 12942; private static int total = 14; private static int[] coff = new int[total]; private static List list = new ArrayList(); private static void copy(int[] a, int[] b) {
for (int i = 0; i < a.length; i++) {
a[i] = b[i];
}
} public static void Package(int index) {
if (index == total) {
int s = getSum(coff);
if(s== sum1) {
show(sum1, coff);
}
if (s == sum2) {
show(sum2, coff);
}
return;
}
for (int i = 0; i < 2; i++) {
coff[index] = i;
Package(index + 1);
} } public static void main(String[] args)throws Exception {
Package(0);
PrintWriter out = new PrintWriter(new FileWriter("c:/1.txt"));
Collections.sort( list);
for(int i=0;i<list.size();i++){
out.println(list.get(i));
}
out.flush() ;
out.close();
} public static void show(int s, int[] coff) {
System.out.print(s + ":");
for (int i = 0; i < coff.length; i++) {
System.out.print(coff[i] * a[i] + " ");
}
System.out.println();
} public static int getSum(int[] coff) {
int res = 0;
for (int i = 0; i < coff.length; i++) {
res += coff[i] * a[i];
}
list.add(new Integer(res));
return res;
}}