HDU 5074 Hatsune Miku (14 Anshan semi-finals e) DP

Source: Internet
Author: User

Given a sequence, the number of digits is unknown. If the two numbers obtain the energy continuously, ask how to arrange the number to maximize the total energy.

Solution: DP is only related to the last letter.

Solution code:

1 // file name: E. CPP 2 // Author: darkdream 3 // created time: wednesday, October 22, 2014, 10 seconds, 4 5 # include <vector> 6 # include <list> 7 # include <map> 8 # include <set> 9 # include <deque> 10 # include <stack> 11 # include <bitset> 12 # include <algorithm> 13 # include <functional> 14 # include <numeric> 15 # include <utility> 16 # include <sstream> 17 # include <iostream> 18 # include <iomanip> 19 # include <cstdio> 20 # include <cmath> 21 # Include <cstdlib> 22 # include <cstring> 23 # include <ctime> 24 # define ll long long25 26 using namespace STD; 27 int DP [200] [60]; 28 int MP [60] [60]; 29 int main () {30 int t; 31 scanf ("% d", & T); 32 While (t --) 33 {34 memset (MP, 0, sizeof (MP); 35 memset (DP,-1, sizeof (DP); 36 int n, m; 37 scanf ("% d", & N, & M); 38 for (INT I = 1; I <= m; I ++) 39 For (Int J = 1; j <= m; j ++) 40 scanf ("% d", & MP [I] [J]); 41 int T; 42 scanf ("% d", & T); 43 DP [1] [T] = 0; 44 If (t =-1) 45 for (INT I = 1; I <= m; I ++) 46 DP [1] [I] = 0; 47 for (INT I = 2; I <= N; I ++) 48 {49 scanf ("% d", & T); 50 if (t =-1) 51 {52 for (Int J = 1; j <= m; j ++) 53 {54 if (DP [I-1] [J]! =-1) 55 for (int s = 1; S <= m; s ++) 56 DP [I] [s] = max (DP [I] [s], DP [I-1] [J] + MP [J] [s]); 57} 58} else {59 for (int s = 1; S <= m; s ++) 60 {61 If (DP [I-1] [s]! =-1) 62 DP [I] [T] = max (DP [I] [T], DP [I-1] [s] + MP [s] [T]); 63} 64} 65 // For (Int J = 1; j <= m; j ++) 66} 67 int MX =-1; 68 for (INT I = 1; I <= m; I ++) 69 If (DP [N] [I]> MX) 70 MX = DP [N] [I]; 71 printf ("% d \ n", MX); 72 73} 74 return 0; 75}
View code

 

HDU 5074 Hatsune Miku (14 Anshan semi-finals e) DP

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.