HDU 5074-Hatsune Miku(DP)
Hatsune Miku
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 29 Accepted Submission(s): 25
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?
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.
2
5 3
83 86 77
15 93 35
86 92 49
3 3 3 1 2
10 5
36 11 68 67 29
82 30 62 23 67
35 29 2 22 58
69 67 93 56 11
42 29 73 21 19
-1 -1 5 -1 4 -1 -1 -1 4 -1
270
625鞍山现场赛的第二道水题。。 。设状态dp[i][k]表示第i个位置放编号为k的物品,则dp[i][k]=max(dp[i][k],dp[i-1][j]+dis[j][k])枚举第i-1为位置上放置的物品。#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
int n,m,dis[55][55],a[110],dp[110][55];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(dp,-1,sizeof(dp));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
scanf("%d",&dis[i][j]);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
if(a[1]!=-1)
dp[1][a[1]]=0;
else
for(int i=1;i<=m;i++)
dp[1][i]=0;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(dp[i-1][j]!=-1)
{ if(a[i]!=-1)
dp[i][a[i]]=max(dp[i][a[i]],dp[i-1][j]+dis[j][a[i]]);
else
for(int k=1;k<=m;k++)
dp[i][k]=max(dp[i][k],dp[i-1][j]+dis[j][k]);
}
}
}
int ans=-INF;
for(int i=1;i<=m;i++)
ans=max(ans,dp[n][i]);
printf("%d\n",ans); }
return 0;
}
HDU 5074-Hatsune Miku(DP)的更多相关文章
- HDU 5074 Hatsune Miku(DP)
Problem Description Hatsune Miku is a popular virtual singer. It is very popular in both Japan and C ...
- hdu - 5074 Hatsune Miku (简单dp)
有m种不同的句子要组成一首n个句子的歌,每首歌都有一个美丽值,美丽值是由相邻的句子种类决定的,给出m*m的矩阵map[i][j]表示第i种句子和第j种句子的最大得分,一首歌的美丽值是由sum(map[ ...
- dp --- 2014 Asia AnShan Regional Contest --- HDU 5074 Hatsune Miku
Hatsune Miku Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5074 Mean: 有m种音符(note),现在要从 ...
- hdu 5074 Hatsune Miku DP题目
题目传送门http://acm.hdu.edu.cn/showproblem.php?pid=5074 $dp[i][j] =$ 表示数列前$i$个数以$j$结尾的最大分数 $dp[i][j] = - ...
- HDU 5791:Two(DP)
http://acm.hdu.edu.cn/showproblem.php?pid=5791 Two Problem Description Alice gets two sequences A ...
- HDU 4833 Best Financing(DP)(2014年百度之星程序设计大赛 - 初赛(第二轮))
Problem Description 小A想通过合理投资银行理财产品达到收益最大化.已知小A在未来一段时间中的收入情况,描述为两个长度为n的整数数组dates和earnings,表示在第dates[ ...
- HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水
简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- hdu 5074 Hatsune Miku
http://acm.hdu.edu.cn/showproblem.php?pid=5074 题意:给你一个的矩阵score[i][j],然后给你一个数列,数列中有一些是-1,代表这个数可以换成1~m ...
- HDU 4833 Best Financing (DP)
Best Financing Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- Leetcode:find_minimum_in_rotated_sorted_array
一. 题目 给定一个排好序的数组.数组可能是单调递增,也可能有一个变换. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2) 要求找出最小的数. ...
- ALV前导零的问题
ALV的IT_FIELDCAT参数中L_ZERO 选项置位的话,对NUM类型的前导0是可以输出的,但是有个很重要的前提条件,NO_ZERO不可以置位,否则L_ZERO是失效的.
- Net基础恶补
一 自定义事件 1 之前一直都是使用事件调用来触发事件,看代码 // 定义一个事件 public event EventHandler; //触发事件 public void OnEvent(){ i ...
- Servlet过滤器——使用过滤器禁止浏览器缓存页面
1.概述 IE缓存虽然能提高已储存网站的访问速度,但是过度的IE缓存会影响浏览器的响应速度.同时还可能为网站的运行带来一些不必要的麻烦.例如:可能会因为浏览器缓存的应用,而导致Web服务器不能准确的计 ...
- 在springmvc中配置jedis(转)
主要学习https://github.com/thinkgem/jeesite.一下代码均参考于此并稍作修改. 1.jedis 首先,需要添加jedis: <!--jedis--> < ...
- 阻塞队列BlockingQueue用法(转)
多线程环境中,通过队列可以很容易实现数据共享,比如经典的“生产者”和“消费者”模型中,通过队列可以很便利地实现两者之间的数据共享. 假设我们有若干生产者线程,另外又有若干个消费者线程.如果生产者线程需 ...
- H2内存数据库 支持存储到文件
准备工作 1.下载JDK(本人下载的版本号为JDK1.7).环境变量设置JAVA_HOME.设置PATH(%JAVA_HOME%\bin%). 2.下载并解压:h2-2014-07-13.zip ...
- 关于vs2005 __RPC__out __RPC__in 没有定义编译错误
1. 下载WDK http://www.microsoft.com/en-us/download/details.aspx?id=11800 2. 安装WDK 3. vs2005 设置:工具--> ...
- Swift - AnyObject与Any的区别
1,AnyObject :代表任何class类型的对象实例. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class Man{ } class Woman{ ...
- c++在string类源
一:回想 (1)c++中的string类是在面试中和笔试中常常考的题目: project代码免费下载 string类的自行实现 (2)c++中的string类和fstream类合起来是处理外部数据的利 ...