intgetMostGold(int n, int w, int[] g,int[] p){ int[] preRusults = newint[p.length]; int[] results = newint[p.length];
// loop for n of workers for(int i=1;i<=w;i++){ if(i<p[0]) preRusults[i]=0; else preRusults[i]=g[0]; }
// loop for n of mines for(int i=0;i<n;i++){ // loop for n of workers for(int j=1;j<=w;j++){ if(j<p[i]) results[j]=preRusults[j]; else results[j]=Math.max(preRusults[j],preRusults[j-p[i]]+g[i]); } preRusults=results; } return results[w]; }
int[] f = newint[length+1]; f[0]=0; // 初始化动态规划的初始值 f[1]=1; f[2]=2; f[3]=3; int result =0; for(int i=4;i<=length;i++){ int max=0; for(int j=1;j<i/2;j++){ int num = f[j]*f[i-j]; if(max<num) max = num; f[i]=max; } } result=f[length]; return result; }