Hatsune Miku
Time limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 622 Accepted Submission (s): 447
Problem Descriptionhatsune Miku is a popular virtual singer. It is very popular in both Japan and China. Basically it is a computer software this 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 is only m different notes provided in the package. And you want the song with n notes.
Also, know that there are a system to evaluate the beautifulness of a song. For each of the consecutive notes A and B, if B comes after a, then the beautifulness for these the notes are evaluated as SCO Re (A, b).
So the total beautifulness for a song consisting of notes A1, A2, ..., an, was simply the sum of score (AI, ai+1) for 1≤ I≤n-1.
Now, your find that at some positions, the notes has to be some specific ones, but at other positions can decide what Notes to use. You want to maximize your song ' s beautifulness. What's the maximum beautifulness you can achieve?
Inputthe first line contains an integer T (t≤10), denoting the number of the the test cases.
For each test case, the first line contains the 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 Y OU cannot change, while negative integers is what you can replace with arbitrary notes. The notes is 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
Source2014 Asia Anshan Regional Contest
recommendliuyiding | We have carefully selected several similar problems for you:5140 5137 5136 5135 5134
DP, one-eye question
#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm>using namespace Std;int dp[110][55];int mat[110][110];int rule[110] ; int main () {int T, N, m;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n, &m); int ans = 0;memset (dp,0, sizeof (DP) ); for (int i = 1; I <= m; ++i) {for (int j = 1; j <= m; ++j) {scanf ("%d", &mat[i][j]);}} for (int i = 1; I <= n; ++i) {scanf ("%d", &rule[i]);} for (int i = 2; I <= n; ++i) {if (rule[i]! =-1) {if (rule[i-1]! =-1) {Dp[i][rule[i]] = dp[i-1][rule[i-1]] + mat[ru Le[i-1]][rule[i]];continue;} for (int j = 1; j <= m; ++j) {dp[i][rule[i]] = max (Dp[i][rule[i]], dp[i-1][j] + mat[j][rule[i]]);}} else{for (int j = 1; j <= m; ++j) {if (rule[i-1]! = 1) {Dp[i][j] = Dp[i-1][rule[i-1]] + mat[rule[i-1]][j];} Else{for (iNT k = 1; K <= m; ++K) {Dp[i][j] = max (Dp[i][j], dp[i-1][k] + mat[k][j]);}}}} for (int i = 1; I <= m; ++i) {ans = max (ans, dp[n][i]);} printf ("%d\n", ans);} return 0;}
Hdu5074--hatsune Miku