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) ...
随机推荐
- UVA 10201 Adventures in Moving - Part IV(dp)
Problem A: Adventures in Moving - Part IV To help you move from Waterloo to the big city, you are co ...
- TObject简要说明-对象的创建流程
TObject = class //创建 constructor Create; //释放 procedure Free; //初始化实列 class functi ...
- ie 64bit调用activex控件
1,首先,这是可能的.不要被网上一堆ie64调不了activex控件的文章误导了.flash就是一个现成的例子,flash支持ie64. 2,ie64只能调用64bit的activex控件.网上那些说 ...
- jeecg智能开发平台参与-2013年度中国优秀开源项目评比
JEECG正在参与<2013年度中国十大优秀开源项目> 评比,如果大家觉得JEECG还不错, 请投出你宝贵的一票,给我们以支持吧!!! [目前排名第8位] https://code.csd ...
- CABasicAnimation学习Demo 包含了一些经常使用的动画效果
个人写的一些样例: // // ViewController.m // CABasicAnimationDemo // // Created by haotian on 14-6-13. // Cop ...
- 【deep learning学习笔记】注释yusugomori的LR代码 --- LogisticRegression.h
继续看yusugomori的代码,看逻辑回归.在DBN(Deep Blief Network)中,下面几层是RBM,最上层就是LR了.关于回归.二类回归.以及逻辑回归,资料就是前面转的几篇.套路就是设 ...
- 【ASP.NET Web API教程】5.3 发送HTML表单数据:文件上传与多部分MIME
原文:[ASP.NET Web API教程]5.3 发送HTML表单数据:文件上传与多部分MIME 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本系列教程,请先看前面 ...
- win7下让程序默认以管理员身份运行
在win7中用自己写的程序读取MBR时,突然提示无法对磁盘进行操作,而在xp下并没有这个问题:最后点右键以管理员身份运行才可以正常运行.于是想办法让程序在双击启动时默认以管理员身份运行.具体方法: 1 ...
- disruptor流程
这里先不提那些编译器方面的优化.只看一下基于无锁环形队列的生产者消费者模型的工作流程.上一个图先: 当中,buffer是一个数组,用来模拟环形队列. slowest_reader记录最慢的reader ...
- HDU--杭电--4502--吉哥系列故事——临时工计划--背包--01背包
吉哥系列故事——临时工计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...