• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

动感三部曲:

1.确定dp下标和dp数组的含义。

2.确定递归关系。

3.确定初始化参数。

4.确定遍历顺序。

5.用示例导出dp数组

1.01背包问题

二维差压:

for(int I=0;I nums . size();我)

for(int j=nums;j=bagsizej)

dp[j]=max(dp[i-1][j],DP[I-1][j-nums]value);

一维dp:内层由大到小遍历

for(int I=0;I nums . size();我)

for(int j=bagsize;j=nums;j -)

dp[j]=max(dp[j],DP[j-nums]value);

二。完整的背包问题

从小到大遍历内层

for(int I=0;I nums . size();我)

for(int j=nums;j=bagsizej)

dp[j]=max(dp[j],DP[j-nums]value);

小贴士:

1.组合问题:递推公式为DP[j]=DP[j-nums];

2.排列问题:递推公式为DP[j]=DP[j-nums];并且在遍历物品之前需要遍历背包。

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now