|
|
вернуться в форумtrie+dp solve it with c++ algo are: dp[i,j]=dp[i,k]&&dp[k+1,j] main code are: for(length=0;length<n;length++) { for(i=0;i+length<n;i++) { if(find(i,i+length,maintree)) { dp[i][i+length][0]=9999; dp[i][i+length][1]=1; save[i][i+length]=choose; } else { bestadd=100;bestj=-1; for(j=i+1;j<i+length;j++) if(dp[i][j][0]!=-1&&dp[j+1][i+length][0]!=-1) { if(dp[i][j][1]+dp[j+1][i+length][1]<=bestadd) { bestadd=dp[i][j][1]+dp[j+1][i+length][1]; bestj=j; } } dp[i][i+length][0]=bestj; dp[i][i+length][1]=bestadd; } } } hope it will do you a favor Re: trie+dp Послано twoon 16 окт 2012 10:05 nice work! |
|
|