Practice for Microsoft 2015 Online Test register

Ended

Participants:1406

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-18 12:02:56

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>
#include <map>
using namespace std;
//best(i, x)ix
int Knapsack(vector<int> need, vector<int> values, int ticket)
{
    /* best[0][j]=0, 1-N*/
    vector< vector<int> > best(need.size(),vector<int>(ticket+1));
    for (int i=1; i< need.size(); i++)
    {
        for (int j=0; j<=ticket; j++)
        {
            /*NNM*/
            if( j < need[i] ) best[i][j]=best[i-1][j];
            else
            {
                best[i][j]=max( best[i-1][j], best[i-1][j-need[i]]+values[i] );
            }
        }
    }
    return best[need.size()-1][ticket];
}
/**/
int Knapsack2(vector<int> need, vector<int> values, int ticket)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX