The main topic: give you some notes between the link, give you a string, let you find out the maximum value of this string. -1 can be arbitrarily substituted, other cases must be the number on the sequence.
Problem-Solving ideas: Simple two-dimensional DP, the situation can be processed.
Hatsune MikuTime
limit:2000/1000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 637 Accepted Submission (s): 458
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
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <ctime> #include <map> #include <set> #define EPS 1e-9///#define M 1000100///#define ll __int64#define ll Long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero (x) ((FA BS (x) <eps)? 0:x) #define MoD 1000000007using namespace std;const int maxn = 110;int Dp[maxn][maxn];int MP[MAXN][MAXN]; int Num[maxn];int Main () {int T; CIN >>T; while (t--) {int n, m; scanf ("%d%d", &m, &n); for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +) scanf ("%d", &mp[i][j]); for (int i = 1; I <= m; i++) scanf ("%d", &num[i]); memset (DP, 0, sizeof (DP)); for (int i = 2; I <= m; i++) {if (num[i-1] = = 1) {if (num[i] = = 1) {for (int j = 1; J <= N; j + +) for (int k = 1; k <= N; k++) dp[i][k] = max (Dp[i-1][j]+mp[j][k], dp[i][k]); Continue } for (int j = 1; J <= N; j + +) Dp[i][num[i]] = max (Dp[i][num[i]], dp[i-1][j]+mp[j][num [i]]); Continue if (num[i] = = 1) {for (int j = 1, j <= N; j + +) Dp[i][j] = max (Dp[i][j], dp[i-1][num[i-1]]+mp[num[i-1]][j]); Continue } Dp[i][num[i]] = dp[i-1][num[i-1]]+mp[num[i-1]][num[i]]; } int Max = 0; for (int i = 1; I <= n; i++) max = max (max, dp[m][i]); cout<<max<<endl; } return 0;}
HDU 5074 Hatsune Miku (simple two-dimensional DP)