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),现在要从这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的更多相关文章
- 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy
Galaxy Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...
- 2014 Asia AnShan Regional Contest --- HDU 5078 Osu!
Osu! Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5078 Mean: 略. analyse: 签到题,直接扫一遍就得答 ...
- HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水
简单dp #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- HDU 5073 Galaxy 2014 Asia AnShan Regional Contest 规律题
推公式 #include <cstdio> #include <cmath> #include <iomanip> #include <iostream> ...
- hdu5071 2014 Asia AnShan Regional Contest B Chat
模拟题: add的时候出现过的则不再添加 close的时候会影响到top rotate(Prior.Choose)的时候会影响到top /*============================== ...
- 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] ...
- 2014 ACM-ICPC Asia Anshan Regional Contest(Online Version)
题目I - Osu! - HDU 5078 题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值 #include<stdio.h> #include<math.h> ...
- hdu 5074 Hatsune Miku DP题目
题目传送门http://acm.hdu.edu.cn/showproblem.php?pid=5074 $dp[i][j] =$ 表示数列前$i$个数以$j$结尾的最大分数 $dp[i][j] = - ...
- HDU 5074 Hatsune Miku(DP)
Problem Description Hatsune Miku is a popular virtual singer. It is very popular in both Japan and C ...
随机推荐
- 深入了解STL中set与hash_set,hash表基础
一,set和hash_set简介 在STL中,set是以红黑树(RB-Tree)作为底层数据结构的,hash_set是以哈希表(Hash table)作为底层数据结构的.set可以在时间复杂度为O(l ...
- [转]说说C#的async和await
C# 5.0中引入了async 和 await.这两个关键字可以让你更方便的写出异步代码. 看个例子: public class MyClass { public MyClass() { Displa ...
- 删除数据报ORA-00600: internal error code, arguments: [ktbesc_plugged]
Oracle在删除数据是以下错误: ORA-00600: internal error code, arguments: [ktbesc_plugged], [], [], [], [], [], [ ...
- Windows 2008 利用Filezilla server搭建FTP
Windows 2008 利用Filezilla server搭建FTP, 安装后总是提示Error Connection To Server Lost , 后来,无意中先安装了IIS,再安装file ...
- memcached命令
memcached相对于redis来说,简直简单太多,命令也少很多,一般应用都是使用redis,但了解一下也还是不错的. 具体命令和用法很参见:http://www.runoob.com/memcac ...
- dubbo通信协议之对比
对dubbo的协议的学习,可以知道目前主流RPC通信大概是什么情况,本文参考dubbo官方文档 http://dubbo.io/User+Guide-zh.htm dubbo共支持如下几种通信协议: ...
- webpack 打包时到底如何组织js
问题一:引入前端库,方法也是不一样的 比如 lodash.js ,作为一个 chunk 用 html-webpack-plugin 打包到页面里,会生成一个全局变量 window._ ,在其它 js ...
- 给VMware下的Linux扩展磁盘空间(以CentOS6.3为例)转
#查看挂载点:df -h#显示:文件系统 容量 已用 可用 已用%% 挂载点/dev/mapper/vg_dc01-lv_root 47G 12G 34G 25% /tmpfs 504M 88K 50 ...
- 编译 curl with ssl
安装 openssh后,使用 curl 的 ./configure --with-ssl 时,报错“找不到 ssl”.因为 curl在 /usr/local/ssl的安装目录下找动态连接库.而ssl默 ...
- 物料分类账 [COML] PART 2 - 总体流程
核心流程概要: [1]. 分类账在物料主数据的影响 首先描述下SAP中物料价格的 物料主数据相关的几个点: q价格控制(Price Control): 决定物料计价方式. S 标准价格(Standar ...