Hatsune Miku

Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5074


Mean:

有m种音符(note),现在要从这m种音符中选出n个来组成一首歌,相邻两个音符之间会有一个评分的方式,即score(i,j),而score(i,j)题目已经给出,现在要你按照题目的规定来选出n个音符来使得最终的分数最高。

analyse:

鞍山赛区第二大水题,很简单的dp。

具体思路:dp[i][j]表示第i个音符选择的是第j种。

那么就很容易得出状态转移方程:dp[i][j]=max(dp[i][j],dp[i+1][j]+v[j][k]).(详见代码)

Time complexity: O(n*m*m)

Source code: 

//  Memory   Time
// 1347K 0MS
// by : Snarl_jsb
// 2014-11-15-21.40
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<climits>
#include<cmath>
#define N 1000010
#define LL long long
using namespace std;
/**< dp[i][j]代表第i个note选择第j种 */
int v[60][60],a[105],dp[105][105];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("C:\\Users\\ASUS\\Desktop\\cin.cpp","r",stdin);
// freopen("C:\\Users\\ASUS\\Desktop\\cout.cpp","w",stdout);
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;++i)
for(int j=1;j<=m;++j)
cin>>v[i][j];
for(int i=1;i<=n;++i)
cin>>a[i];
memset(dp,0,sizeof dp);
for(int i=n-1;i>=0;--i)/**< 要选出n个数 */
{
for(int j=0;j<=m;++j)/**< 其中每个数都对应着m选法 */
{
if(a[i+1]<0)/**< 可以自由选 */
{
for(int k=1;k<=m;++k)
dp[i][j]=max(dp[i][j],dp[i+1][k]+v[j][k]);
}
else/**< 已经固定的 */
{
dp[i][j]=v[j][a[i+1]]+dp[i+1][a[i+1]];
}
}
}
cout<<dp[0][0]<<endl;
}
return 0;
}
/*
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
*/

  

dp --- 2014 Asia AnShan Regional Contest --- HDU 5074 Hatsune Miku的更多相关文章

  1. 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy

    Galaxy Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...

  2. 2014 Asia AnShan Regional Contest --- HDU 5078 Osu!

    Osu! Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5078 Mean: 略. analyse: 签到题,直接扫一遍就得答 ...

  3. HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水

    简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...

  4. HDU 5073 Galaxy 2014 Asia AnShan Regional Contest 规律题

    推公式 #include <cstdio> #include <cmath> #include <iomanip> #include <iostream> ...

  5. hdu5071 2014 Asia AnShan Regional Contest B Chat

    模拟题: add的时候出现过的则不再添加 close的时候会影响到top rotate(Prior.Choose)的时候会影响到top /*============================== ...

  6. hdu5072 2014 Asia AnShan Regional Contest C Coprime

    最后一次参加亚洲区…… 题意:给出n(3 ≤ n ≤ 105)个数字,每个数ai满足1 ≤ ai ≤ 105,求有多少对(a,b,c)满足[(a, b) = (b, c) = (a, c) = 1] ...

  7. 2014 ACM-ICPC Asia Anshan Regional Contest(Online Version)

    题目I - Osu! - HDU 5078 题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值 #include<stdio.h> #include<math.h> ...

  8. hdu 5074 Hatsune Miku DP题目

    题目传送门http://acm.hdu.edu.cn/showproblem.php?pid=5074 $dp[i][j] =$ 表示数列前$i$个数以$j$结尾的最大分数 $dp[i][j] = - ...

  9. HDU 5074 Hatsune Miku(DP)

    Problem Description Hatsune Miku is a popular virtual singer. It is very popular in both Japan and C ...

随机推荐

  1. int跟byte[]数组互转的方法,整数 + 浮点型

    整数: int转byte数组 public static byte[] intToBytes2(int n){ ]; ;i < ;i++) { b[i]=(-i*)); } return b; ...

  2. Storage Systems topics and related papers

    In this post, I will distill my own ideas and my own views into a structure for a storage system cou ...

  3. iPhone设备字体详解

    做iPhone开发的同学一定对:UIFont systemFontOfSize.boldSystemFontOfSize.italicSystemFontOfSize很熟悉,但你们知道它们都是什么字体 ...

  4. Navi.Soft30.框架.WebMVC.开发手册

    1概述 1.1应用场景 互联网高速发展,互联网软件也随之越来越多,Web程序越来越被广泛使用.它部署简单,维护方便,深得众多软件公司使用 Bootstrap前端框架,是最近非常流行的框架之一.它简洁, ...

  5. HTML Hyperlink between and within pages

    In HTML, we can use tag <a href=""> to create hyperlinks between and within pages. T ...

  6. java对过反射调用方法

      public class InvokeTester { public InvokeTester() { } String str; public InvokeTester(String str) ...

  7. 聊聊 Linux 中的五种 IO 模型

    本文转载自: http://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666538919&idx=1&sn=6013c451 ...

  8. ThreadPoolExecutor

    ThreadPoolExecutor机制 一.概述 1.ThreadPoolExecutor作为java.util.concurrent包对外提供基础实现,以内部线程池的形式对外提供管理任务执行,线程 ...

  9. 用gameMaker做个小游戏

    看下面这个课程链接,半小时学会 http://study.163.com/course/courseMain.htm?courseId=352004#/courseMain 这是我做的:http:// ...

  10. 最近新装系统windows8.1+Mac。。。还没装驱动就遇到一堆问题。。。

    ---恢复内容开始--- 1,刚开始装好了,后来莫名看不到磁盘了,原因:64位mac盘会丢失盘符,所以macdrive也看不到...解决:(将AF改为06,修改内容后改回AF,早知道这么简单就不用重新 ...