HDU 5074 Hatsune Miku(14鞍山区域赛 E)DP

题意:给定一个序列 有些位数未知,给你如果两个数连续所得到的能量,问你怎么安排数字使得总能量最大

解题思路:dp,只与上一个字母有关。

解题代码:

 1 // File Name: e.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年10月22日 星期三 12时16分10秒
 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 long
25
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 %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 }

时间: 2024-10-05 14:34:32

HDU 5074 Hatsune Miku(14鞍山区域赛 E)DP的相关文章

HDU 5074 Hatsune Miku(2014鞍山赛区现场赛E题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5074 解题报告:给出一个长度为n的序列,例如a1,a2,a3,a4......an,然后这个序列的美丽值就是socre[a1][a2] + socre[a2][a3] + ..... socre[an-1][an],但是这个序列里面并不是所有的数都是确定的,输入包含一些大于0的数和一些-1,-1表示这个数可以任意,但是要在m的范围内,给出socre[i][j],求这个序列最大的美丽值. 一个二维dp

HDU 5071 Chat (14鞍山区域赛 B) 模拟

题意:无力写了. 解题思路:纯模拟 解题代码: 1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2014年10月22日 星期三 15时51分59秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack>

hdu 5073 Galaxy(14鞍山区域赛 D) 二分 + 递推

题意:给定你一条直线,直线上面有n个点,你可以移动k个点,求所有点到重心距离的平方和最小值为多少. 解题思路:这里可以知道 保持一段不移动然后把所有的点都移动到这一段的重心才是最优解,那我们很容易想到枚举这一段的端点,但是如果枚举端点,时间复杂度会高达 n^2,所以我们要知道区间之间的关系,假设 lsum ,rsum  ,lans,rans ,分别为 重心左右的 距离和 和重心左右的平方和,然后每次移动找重心位置,再算 这四个值之间的递推关系就行了. 解题代码: 1 // File Name:

hdu5074 Hatsune Miku 2014鞍山现场赛E题 水dp

http://acm.hdu.edu.cn/showproblem.php?pid=5074 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 325    Accepted Submission(s): 243 Problem Description Hatsune Miku is a popular vi

hdu 5074 Hatsune Miku(2014 鞍山现场赛)

Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 17    Accepted Submission(s): 14 Problem Description Hatsune Miku is a popular virtual singer. It is very popular in both Japan an

HDU 5074 Hatsune Miku

Hatsune Miku Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 507464-bit integer IO format: %I64d      Java class name: Main Hatsune Miku is a popular virtual singer. It is very popular in both Japan and Chin

HDU 5074 Hatsune Miku (线性dp)

Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 654    Accepted Submission(s): 471 Problem Description Hatsune Miku is a popular virtual singer. It is very popular in both Japan

HDU 5074 Hatsune Miku(简单二维dp)

题目大意:给你一些音符之间的联系,给你一个串,让你求出这个串的最大值.-1的时候可以任意替代,其他情况必须为序列上的数. 解题思路:简单二维dp,分情况处理就可以了啊. Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 637    Accepted Submission(s): 458 Problem De

[ACM] HDU 5074 Hatsune Miku (简单DP)

Hatsune Miku Problem Description Hatsune 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 compos

HDU 5074 Hatsune Miku(DP)

Problem Description Hatsune 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, whi