真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java代碼寫(xiě)算法 根據(jù)算法寫(xiě)代碼

用Java寫(xiě)一個(gè)算法,把一串?dāng)?shù)字,所有可能的和按順序排列,并計(jì)算每個(gè)和出現(xiàn)的次數(shù)

樓主你好

我們提供的服務(wù)有:做網(wǎng)站、網(wǎng)站建設(shè)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、遂溪ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢(xún)和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的遂溪網(wǎng)站制作公司

應(yīng)你的要求 我只做了加一位的和加兩位的

算法類(lèi)代碼如下:

public class CountSumClass {

private String number;

private String result = new String("");

public CountSumClass() {

number = new String();

}

public CountSumClass(String str) {

number = str;

}

public String getResult() {

return result;

}

public void addOne() {

int x,y;

for (int i = 0; i number.length()-1; i++) {

x = (int)number.charAt(i) - 48;

for(int j = i+1; jnumber.length(); j++) {

y = (int)number.charAt(j) - 48;

result += x+"+"+y+"="+(x+y)+"\n";

}

}

y=0;

for (int i = 0; inumber.length(); i++) {

x = (int)number.charAt(i) - 48;

y += x;

if(i == number.length()- 1) {

result += x+"="+y;

} else {

result += x+"+";

}

}

}

public void addTwo() {

int x,y,z;

result += "\n";

for (int i = 0; inumber.length()-1; i++) {

String substr = number.substring(i,i+2);

x = Integer.parseInt(substr);

z = (x%10) * 10 + (x/10);

for(int j=0; jnumber.length(); j++) {

if(j!=i j!=i+1) {

y = (int)number.charAt(j) - 48;

result += x+"+"+y+"="+(x+y)+"\n";

result += z+"+"+y+"="+(z+y)+"\n";

}

}

}

}

public String toString() {

return result;

}

}

希望能幫助你哈

JAVA 實(shí)現(xiàn)算法

package huda.laogao.ON_20121216;

import java.util.*;

public class GetEquation {

ArrayListInteger params = null;// 進(jìn)行加減的數(shù),長(zhǎng)度設(shè)為n

int result = 0;// 結(jié)果

public GetEquation(ArrayListInteger params, int result) {

this.params = params;

this.result = result;

}

public void run() {

int size = params.size();

if (size == 1) {

if (params.get(0) == result)

System.out.println(result + "=" + result);

else

System.out.println("Invalid");

return;

}

int[][] matrix = getMatrix(size - 1);

int m = matrix.length;// 行數(shù)

int count = 0;// 記錄符合結(jié)果的組合數(shù)

for (int i = 0; i m; i++) {

int now = params.get(0);// 進(jìn)行加減的結(jié)果,初始為第一個(gè)值

// 從第二個(gè)數(shù)開(kāi)始進(jìn)行加或減,加的話就相當(dāng)于該數(shù)乘上1,然后加到結(jié)果上,

// 減的就相當(dāng)于該數(shù)乘上-1,然后加到結(jié)果上

for (int j = 1; j size; j++) {

now += matrix[i][j - 1] * params.get(j);

}

// System.out.println(now);

// 判斷結(jié)果

if (now == result) {

count++;// 組合數(shù)加1

System.out.print(params.get(0));

for (int j = 1; j size; j++) {

if (matrix[i][j - 1] == 1)

System.out.print("+" + params.get(j));

else

System.out.print("-" + params.get(j));

}// for j

System.out.println("=" + result);

}// if

}// for i

if (count == 0)

System.out.println("Invalid");

}

public int[][] getMatrix(int n) {

int m = (int) Math.pow(2, n);

int matrix[][] = new int[m][n];

for (int i = 0; i n; i++) {

int num = (int) Math.pow(2, i + 1);

// 總共分 2^(i+1)塊,如i=0,即該矩陣的第一列,可分為2塊,上一塊取1,下一塊取-1

int size = (int) Math.pow(2, n - i - 1);

// 每塊的大小為2^(n-i-1),如n=3,i=0,每塊的大小為4,即前4個(gè)為1,后4個(gè)為-1

int flag = 1;// 先為+

for (int j = 0; j num; j++) {

for (int k = 0; k size; k++) {

matrix[k + j * size][i] = flag;

}

flag *= -1;

}

}

return matrix;

}

public void print(int[][] matrix) {

for (int i = 0; i matrix.length; i++) {

for (int j = 0; j matrix[i].length; j++) {

System.out.print(matrix[i][j] + "\t");

}

System.out.println();

}

}

public static void main(String args[]) {

ArrayListInteger params = new ArrayListInteger();

params.add(1);

params.add(2);

params.add(3);

params.add(4);

int result = 10;

GetEquation ge = new GetEquation(params, result);

ge.run();

}

}

運(yùn)行結(jié)果為:1+2+3+4=10

注:難點(diǎn)為獲取加減矩陣,可輔助print()函數(shù)幫助理解

望采納

如何用70行Java代碼實(shí)現(xiàn)深度神經(jīng)網(wǎng)絡(luò)算法

參考下面代碼:

import java.util.Random;

public class BpDeep{

public double[][] layer;//神經(jīng)網(wǎng)絡(luò)各層節(jié)點(diǎn)

public double[][] layerErr;//神經(jīng)網(wǎng)絡(luò)各節(jié)點(diǎn)誤差

public double[][][] layer_weight;//各層節(jié)點(diǎn)權(quán)重

public double[][][] layer_weight_delta;//各層節(jié)點(diǎn)權(quán)重動(dòng)量

public double mobp;//動(dòng)量系數(shù)

public double rate;//學(xué)習(xí)系數(shù)

public BpDeep(int[] layernum, double rate, double mobp){

this.mobp = mobp;

this.rate = rate;

layer = new double[layernum.length][];

layerErr = new double[layernum.length][];

layer_weight = new double[layernum.length][][];

layer_weight_delta = new double[layernum.length][][];

Random random = new Random();

for(int l=0;llayernum.length;l++){

layer[l]=new double[layernum[l]];

layerErr[l]=new double[layernum[l]];

if(l+1layernum.length){

layer_weight[l]=new double[layernum[l]+1][layernum[l+1]];

layer_weight_delta[l]=new double[layernum[l]+1][layernum[l+1]];

for(int j=0;jlayernum[l]+1;j++)

for(int i=0;ilayernum[l+1];i++)

layer_weight[l][j][i]=random.nextDouble();//隨機(jī)初始化權(quán)重

}

}

}

//逐層向前計(jì)算輸出

public double[] computeOut(double[] in){

for(int l=1;llayer.length;l++){

for(int j=0;jlayer[l].length;j++){

double z=layer_weight[l-1][layer[l-1].length][j];

for(int i=0;ilayer[l-1].length;i++){

layer[l-1][i]=l==1?in[i]:layer[l-1][i];

z+=layer_weight[l-1][i][j]*layer[l-1][i];

}

layer[l][j]=1/(1+Math.exp(-z));

}

}

return layer[layer.length-1];

}

//逐層反向計(jì)算誤差并修改權(quán)重

public void updateWeight(double[] tar){

int l=layer.length-1;

for(int j=0;jlayerErr[l].length;j++)

layerErr[l][j]=layer[l][j]*(1-layer[l][j])*(tar[j]-layer[l][j]);

while(l--0){

for(int j=0;jlayerErr[l].length;j++){

double z = 0.0;

for(int i=0;ilayerErr[l+1].length;i++){

z=z+l0?layerErr[l+1][i]*layer_weight[l][j][i]:0;

layer_weight_delta[l][j][i]= mobp*layer_weight_delta[l][j][i]+rate*layerErr[l+1][i]*layer[l][j];//隱含層動(dòng)量調(diào)整

layer_weight[l][j][i]+=layer_weight_delta[l][j][i];//隱含層權(quán)重調(diào)整

if(j==layerErr[l].length-1){

layer_weight_delta[l][j+1][i]= mobp*layer_weight_delta[l][j+1][i]+rate*layerErr[l+1][i];//截距動(dòng)量調(diào)整

layer_weight[l][j+1][i]+=layer_weight_delta[l][j+1][i];//截距權(quán)重調(diào)整

}

}

layerErr[l][j]=z*layer[l][j]*(1-layer[l][j]);//記錄誤差

}

}

}

public void train(double[] in, double[] tar){

double[] out = computeOut(in);

updateWeight(tar);

}

}


本文標(biāo)題:java代碼寫(xiě)算法 根據(jù)算法寫(xiě)代碼
轉(zhuǎn)載來(lái)源:http://weahome.cn/article/hjjssc.html

其他資訊

在線咨詢(xún)

微信咨詢(xún)

電話咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部