poj 3624 Charm Bracelet(区间dp)

题目链接:http://poj.org/problem?id=3624

思路分析:

经典的0-1背包问题:

分析如下:

poj 3624 Charm Bracelet(区间dp)

 

代码如下:

#include <iostream>

using namespace std;



const int MAX_N = 12880 + 10;

int dp[MAX_N], W[MAX_N], D[MAX_N];

int Max( int a, int b ) { return a > b ? a : b; }



int main()

{

    int n, m;



    memset( dp, 0, sizeof(dp) );

    cin >> n >> m;



    for ( int i = 1; i <= n; ++i )

        cin >> W[i] >> D[i];



    for ( int i = 1; i <= n; ++i )

        for ( int j = m; j - W[i] >= 0; --j )

                dp[j] = Max( dp[j], dp[j-W[i]]+D[i]);



    cout << dp[m] << endl;



    return 0;



}

 

你可能感兴趣的:(char)