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) ...
随机推荐
- JQuery Ajax实例总结
jQuery确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯. 废话少说,直接进入正题,我们先来看一些简单的方法,这些方法都是对 ...
- 翻转整数 Reverse digits of a number
两种方法翻转一个整数.顺序翻转和递归翻转 这里没考虑overflow的情况 递归的作用是使得反向处理.即从递归栈的最低端開始处理.通过绘图可得. 假设是rec(num/10): 12345 1234 ...
- 499 - What's The Frequency, Kenneth?
What's The Frequency, Kenneth? #include <stdio.h> main() { int i; char *suffix[]= { "st ...
- 基于visual Studio2013解决面试题之0306打印第一次只出现一次的字符
题目
- Oracle死锁、数据库链接问题
--查询数据库锁表的信息 select do.object_name,t2.username,t2.sid,t2.serial#,t2.logon_time,t2.MACHINE,t2.state,t ...
- 在Qt中使用ActiveX控件
Qt的windows商业版本提供了ActiveQt这个framework,使用这个组件我们可以在Qt中使用ActiveX控件,并且也开发基于Qt的ActiveX控件.ActiveQt包含了两个组件QA ...
- Windows消息队列
一 Windows中有一个系统消息队列,对于每一个正在执行的Windows应用程序,系统为其建立一个“消息队列”,即应用程序队列,用来存放该程序可能 创建的各种窗口的消息.应用程序中含有一段称作“消息 ...
- Linux I/O 重定向详解及应用实例
Linux I/O 重定向详解及应用实例 简解 > 输出 < 输入 >> 追加 & [> | < | >>]之前:输入输出; ls /dev & ...
- Hibernate获取Connection
package com.trendcom.base.util; import java.sql.Connection; import java.sql.SQLException; import jav ...
- Oauth认证的时候报错:timestamp_refused
今天server大规模报错,大部分用户无法登陆,小部分能够登陆,非常是奇怪. 查看log.调试代码,发现问题是在oauth认证的时候出了问题,报 timestamp_refused. google了下 ...