Poj2184cow Exhibition (01 backpack variant)

Source: Internet
Author: User

Thought suddenly thought, transfer equation but did not think well, see on-line a way of thinking the same code, change the transfer equation.

At the same time DP all initialized to negative infinity, need to pay attention to.

The AC code is as follows:

/**************************************************memory:1884 kbtime:250 mslanguage:g++result:accepted********* /#include <iostream> #include <cstdio> #include <cstring >using namespace std;/** title Description: N Cow (1-n), each ox has two values Si and fi, select any of them, make S and F's and Max, where S and f each and both cannot be negative */int s[105], F[105];int dp[    200005];int num[200005];const int INF = 0x5f5f5f5f;int Main () {int n;        while (CIN >> N) {int m = 0;            for (int i = 0; i < n; ++i) {cin >> s[i] >> f[i];   S[i] + = 1000;        All plus 1000 guaranteed non-negative m + = s[i];        } for (int i = 0; I <= m; ++i) dp[i] =-inf;        memset (num, 0, sizeof num);      Dp[0] = 0;        Ensure that all DP values are exactly full. for (int i = 0, i < n; ++i) {for (int j = m; J >= S[i];--j) {//if (Dp[j] < Dp[j-s[i]] + f[i]) if (Dp[j]-num[j] * < Dp[j-s[i]] + f[i]-(Num[j-s[i]] + 1) * 1000) {//This transfer equation I was drunk, too.                    Guaranteed is s and for J time S and F's and max dp[j] = dp[j-s[i]] + f[i];     NUM[J] = Num[j-s[i]] + 1;                Record how many cows are used.            }//printf ("dp[%d]=%d, num[%d]=%d\n", J, Dp[j],j, Num[j]);        }} int ans = 0;                for (int j = 0; j <= m; ++j) {if (Dp[j] >= 0 && j-num[j] * + >= 0)        ans = max (ans, dp[j] + j-num[j] * 1000);    } cout << ans << endl; } return 0;}

  

Poj2184cow Exhibition (01 backpack variant)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.