HDU 2670 Girl Love Value Dynamic Planning

Source: Internet
Author: User
/* Once we see the range of N and K and the type of the question, we should think of the relationship with DP, first sort by Bi from large to small (descending and quick early election, here is the greedy idea) DP [I] [J] indicates that the first I took the maximum value that can be reached by J, then the transfer equation is DP [I] [J] = max (DP [I-1] [J], DP [I-1] [J-1] + AI-(J-1) * bi ); */# include <vector> # include <map> # include <set> # include <deque> # include <stack> # include <bitset> # include <algorithm> # include <functional> # include <numeric> # include <utility> # include <sstream> # include <iostream> # include <iomanip> # include <cstdio> # include <queue> # I Nclude <cmath> # include <cstdlib> # include <cstring> # include <ctime> # include <string> using namespace STD; int N, K; struct point {int, b;} p [100009]; bool CMP (point X, point y) {return X. b> Y. b;} int DP [100009] [1009]; int main () {While (scanf ("% d", & N, & K )! = EOF) {for (INT I = 1; I <= N; I ++) scanf ("% d", & P [I]. a); For (INT I = 1; I <= N; I ++) scanf ("% d", & P [I]. b); Int J = 0, ANS = 0; sort (p + 1, P + n + 1, CMP); For (INT I = 0; I <= N; I ++) DP [I] [0] = 0; For (INT I = 1; I <= N; I ++) {for (Int J = 1; j <= I & J <= K; j ++) DP [I] [J] = max (DP [I-1] [J], DP [I-1] [J-1] + (P [I]. a-(J-1) * P [I]. b);} printf ("% d \ n", DP [N] [k]);}

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.