Links: http://acm.nyist.net/JudgeOnline/problem.php?pid=541
A few days ago, Baidu after the problem with the mathematical knowledge of AC, and later Daniel said this is a dynamic planning problems.
On-line math problem solving Links: http://blog.csdn.net/x314542916/article/details/8204583
D (i) = Max{d (j) *d (n-j) | 1<= J <=n/2};
Writing in Java is relatively straightforward
import Java.math.biginteger;import Java.util.Scanner; Public classmain{FinalintN =1010; BigInteger d[]=NewBiginteger[n]; Scanner Cin=NewScanner (System.inch); Public Static voidMain (string[] args) {intT, N; T=Cin.nextint (); for(intI=0; i<n; i++) D[i]=NewBigInteger ("0"); for(intI=1; i<=n-2; i++) {D[i]=biginteger.valueof (i); for(intj=1; j<=i/2; J + +) {D[i]= D[i].max (D[j].multiply (d[i-j])); } } while(t-->0) {n=Cin.nextint (); System. out. println (D[n].tostring ()); } }}
Use mathematical knowledge of the problem solving code:
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>using namespacestd;#defineINF 0x7fffffff#defineN 10000#defineMOD 10intAns[n];voidMutify (intN) { if(N <=0)return; for(intI=0; i<n; i++){ intc =0; for(intk=0; k<n; k++) {Ans[k]= ans[k]*3+C; C= ans[k]/MOD; if(Ans[k] >=MOD) Ans[k]%=MOD; } } }voidMutiintN) { for(intI=0; i<n; i++) Ans[i]= ans[i]*N; intc =0; for(intI=0; i<n; i++) {Ans[i]= ans[i]+C; C= ans[i]/MOD; Ans[i]%=MOD; } }intMain () {intT, M, N; CIN>>T; while(t--) {memset (ans,0,sizeof(ans)); ans[0] =1; CIN>>m; if(m%3!=1) {mutify (M/3); }Else{//if (m%3 = = 1)Mutify (m/3-1); if(M >1) Muti (4); } if(m%3==2) {Muti (2); } intK = n1; while(Ans[k] = =0) k--; for(intI=k; i>=0; i--) {cout<<Ans[i]; } cout<<Endl; } return 0;}
[Henan Province ACM Province-fifth session] the strongest de combat effectiveness (NYOJ 541)