HDU 5074 Hatsune Miku (dp), hduhatsune

Source: Internet
Author: User

HDU 5074 Hatsune Miku (dp), hduhatsune

Problem DescriptionHatsune Miku is a popular virtual singer. It is very popular in both Japan and China. Basically it is a computer software that allows you to compose a song on your own using the vocal package.

Today you want to compose a song, which is just a sequence of notes. There are only m different notes provided in the package. And you want to make a song with n notes.


Also, you know that there is a system to evaluate the beautifulness of a song. for each two consecutive notes a and B, if B comes after a, then the beautifulness for these two notes is evaluated as score (a, B ).

So the total beautifulness for a song consisting of notes a1, a2 ,..., an, is simply the sum of score (ai, ai + 1) for 1 ≤ I ≤ n-1.

Now, you find that at some positions, the notes have to be some specific ones, but at other positions you can decide what notes to use. you want to maximize your song's beautifulness. what is the maximum beautifulness you can achieve?
InputThe first line contains an integer T (T ≤ 10), denoting the number of the test cases.

For each test case, the first line contains two integers n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 50) as mentioned above. then m lines follow, each of them consisting of m space-separated integers, the j-th integer in the I-th line for score (I, j) (0 ≤ score (I, j) ≤ 100 ). the next line contains n integers, a1, a2 ,..., an (-1 ≤ ai ≤ m, ai =0), where positive integers stand for the notes you cannot change, while negative integers are what you can replace with arbitrary notes. the notes are named from 1 to m.
OutputFor each test case, output the answer in one line.
Sample Input
25 383 86 7715 93 3586 92 493 3 3 1 210 536 11 68 67 2982 30 62 23 6735 29 2 22 5869 67 93 56 1142 29 73 21 19-1 -1 5 -1 4 -1 -1 -1 4 -1
 
Sample Output
270625
 
Question (CITE others' explanations)

There are m kinds of notes, numbers 1 to m. We need to use these m kinds of notes to create a song with n notes (of course, one note can be used multiple times ), suppose there are two consecutive notes I, j. Then, the score (I, j) is defined as the score of the two notes. All the scores (I, j) are given in advance in the question) 1 <= I, j <= m, then the score of the n-note is score (note [I], note [I + 1]). + score (note [I + 1], note [I + 2) + ...... score (note [n-1], note [n]), I starts from 1. Note [I] indicates the number of the I-th notes in the n-th note. 1 <= note [I] <= m, for example, note [I] = 3, it indicates that the I-th place in n Notes uses 3rd kinds of notes (a total of m types). The n notes are given in advance, note [1] to note [n], note [I] is either-1 or greater than or equal to 1 or less than or equal to m. For the latter, the notes at this position cannot be changed. For the former, this position can be changed to any j (1 <= j <= m), and the maximum score of the n notes is asked.


In the code, I paste a correct code and a code with a bug:


Code:


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <queue> # include <stack> # include <vector> # define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8using namespace std; # define N 105int B [N] [N], a [N]; int n, m; int dp [N] [N]; // dp [I] [j] indicates the maximum value of void solve () {int I, j, k; memset (dp, 0, sizeof (dp); for (I = 2; I <= n; I ++) if (a [I] <0) {if (a [I-1] <0) {for (j = 1; j <= m; j ++) for (k = 1; k <= m; k ++) dp [I] [j] = max (dp [I] [j], dp [I-1] [k] + B [k] [j]);} else {for (k = 1; k <= m; k ++) dp [I] [k] = max (dp [I] [k], dp [I-1] [a [I-1] + B [a [I-1] [k]);} else {if (a [I-1]> 0) {dp [I] [a [I] = dp [I-1] [a [I-1] + B [a [I-1] [a [I];} else {for (k = 1; k <= m; k ++) dp [I] [a [I] = max (dp [I] [a [I], dp [I-1] [k] + B [k] [a [I]) ;}} int main () {int I, j, t; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & m); memset (B, 0, sizeof (B); for (I = 1; I <= m; I ++) for (j = 1; j <= m; j ++) scanf ("% d", & B [I] [j]); for (I = 1; I <= n; I ++) scanf ("% d ", & a [I]); solve (); int ans = 0; for (I = 1; I <= m; I ++) ans = max (ans, dp [n] [I]); printf ("% d \ n", ans);} return 0 ;}


Bug code:


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <queue> # include <stack> # include <vector> # define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8using namespace std; # define N 105int B [N] [N], a [N]; int n, m; int dp [N] [N]; void solve () {int I, j, k; memset (dp, 0, sizeof (dp); for (I = 2; I <= n; I ++) if (a [I] <0) // bug is here, there is no classification for a [I-1], that is, a [I-1] is a value, although dp [I-1] [x] is 0, B [x] [j] // very large, so strict classification is required {for (j = 1; j <= m; j ++) for (k = 1; k <= m; k ++) dp [I] [j] = max (dp [I] [j], dp [I-1] [k] + B [k] [j]);} else {if (a [I-1]> 0) {dp [I] [a [I] = dp [I-1] [a [I-1] + B [a [I-1] [a [I];} else {for (k = 1; k <= m; k ++) dp [I] [a [I] = max (dp [I] [a [I], dp [I-1] [k] + B [k] [a [I]) ;}} int main () {int I, j, t; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & m); memset (B, 0, sizeof (B); for (I = 1; I <= m; I ++) for (j = 1; j <= m; j ++) scanf ("% d", & B [I] [j]); for (I = 1; I <= n; I ++) scanf ("% d ", & a [I]); solve (); int ans = 0; for (I = 1; I <= m; I ++) ans = max (ans, dp [n] [I]); printf ("% d \ n", ans);} return 0 ;}





Hatsune miku is the future of hatsune.

300 heads? Don't lie to you. There are at least 30000 original tracks on nico.

I have a 300 initial sound on my ipod, most of which are my favorite albums. If you want to, I will send you the list.

MIKU is called the initial sound len rin is called the mirror sound LUKA is called the patrol sound gumi is what?

Hatsune miku)
Likewise, the kagamine rin operator (kagamine ren) patrol operator (megurine ruka) is the full name.
The full name of gumi is called "batch upload (gumi)", so no

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.