HDU 5074 Hatsune Miku(dp)

DDS信号发生器设计避坑指南:从AD9834配置到巴特沃斯滤波实战 本文详细解析了基于AD9834芯片的DDS信号发生器设计中的关键技术要点与常见陷阱,涵盖时钟源选择、寄存器配置时序、巴特沃斯滤波器设计等核心内容。针对中高频段信号质量优化,提供了实用的解决方案和代码示例,帮助工程师规避设计误区,提升信号发生器的性能和稳定性。 阅读详情

Problem Description
Hatsune Miku is a popular virtual singer. It is very popular in both Japan and China. Basically it is a computer software that allows you to compose a song on your own using the vocal package.

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?
 

Input
The first line contains an integer T (T ≤ 10), denoting the number of the test cases.

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.
 

Output
For each test case, output the answer in one line.
 

Sample Input
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
 

Sample Output
270 625
 

题意:(引用别人的解释)

  题意为有m种音符,编号1到m,我们要用这m种音符来创造一首带有n个音符的曲子(当然,一种音符可以用多次),假设有两个连续的音符 i ,j ,那么定义score(i,j)为这两个音符的得分,题目中预先给出所有的score(i,j)   1<=i,j<=m, 那么我们创造出的n个音符的曲子的得分为  score( note[i] , note[i+1] ) + score (note[i+1] ,note[i+2) +......score(note[n-1],note[n]) , i从1开始。 note [i] 代表n个音符的曲子中第i个音符是第几种音符, 1<=note[i]<=m, 比如 note[i]=3,就表示n个音符中第i个位置用的是第3种音符(一共有m种),预先给出 这n个音符,note[1] 到note[n] ,其中note[ i] 或者等于-1 ,或者 大于等于1小于等于m,对于后者,该位置的音符不能改变,对于前者,该位置可以换成任意的音符j(1<=j<=m), 问 这n个音符所获得的最大得分是多少。


解释在代码中,这里我贴出来一个对的和一个有bug的代码:


对的代码:


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
using namespace std;
#define N 105

int b[N][N],a[N];
int n,m;
int dp[N][N];   //dp[i][j]表示长度为i,以j结尾的最大价值

void solve()
{
	int i,j,k;
	memset(dp,0,sizeof(dp));

	for(i=2;i<=n;i++)
	   if(a[i]<0)
	   {
	       if(a[i-1]<0)
         	{
             for(j=1;j<=m;j++)
		       for(k=1;k<=m;k++)
			     dp[i][j]=max(dp[i][j],dp[i-1][k]+b[k][j]);
         	}
         	else
            {
               for(k=1;k<=m;k++)
                  dp[i][k]=max(dp[i][k],dp[i-1][a[i-1]]+b[a[i-1]][k]);
            }
	   }
	   else
	   {
           if(a[i-1]>0)
	   	    {
                dp[i][a[i]]=dp[i-1][a[i-1]]+b[a[i-1]][a[i]];
	   	    }
	   	    else
            {
                for(k=1;k<=m;k++)
                dp[i][a[i]]=max(dp[i][a[i]],dp[i-1][k]+b[k][a[i]]);
            }
	   }
}

int main()
{
	int i,j,t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		memset(b,0,sizeof(b));

		for(i=1;i<=m;i++)
			for(j=1;j<=m;j++)
			 scanf("%d",&b[i][j]);

		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);

		solve();

		int ans=0;
		for(i=1;i<=m;i++)
			ans=max(ans,dp[n][i]);

		printf("%d\n",ans);
	}
    return 0;
}


有bug代码:


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
using namespace std;
#define N 105

int b[N][N],a[N];
int n,m;
int dp[N][N];

void solve()
{
    int i,j,k;
    memset(dp,0,sizeof(dp));

    for(i=2;i<=n;i++)
       if(a[i]<0)     //bug就在这里,没有对a[i-1]分类,就是a[i-1]为定值,虽然dp[i-1][x]为0,但是b[x][j]//很大,所以需要严格的分类
       {
             for(j=1;j<=m;j++)
              for(k=1;k<=m;k++)
                dp[i][j]=max(dp[i][j],dp[i-1][k]+b[k][j]);
       }
       else
       {
           if(a[i-1]>0)
               {
                dp[i][a[i]]=dp[i-1][a[i-1]]+b[a[i-1]][a[i]];
               }
               else
            {
                for(k=1;k<=m;k++)
                dp[i][a[i]]=max(dp[i][a[i]],dp[i-1][k]+b[k][a[i]]);
            }
       }
}

int main()
{
    int i,j,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        memset(b,0,sizeof(b));
        
        for(i=1;i<=m;i++)
            for(j=1;j<=m;j++)
             scanf("%d",&b[i][j]);

        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);

        solve();

        int ans=0;
        for(i=1;i<=m;i++)
            ans=max(ans,dp[n][i]);

        printf("%d\n",ans);
    }
    return 0;
}




一文就够-InfiniBand 技术全面解析:从原理到实践的通俗易懂指南 想象一下,在一个超级数据中心里,成千上万台服务器需要像蜜蜂群体一样高效协作。如果用传统的网络连接,就像让每只蜜蜂都排着队传递消息,效率极低。InfiniBand(简称 IB)就是为了解决这种 "通信拥堵" 而生的高速网络技术,它专门为高性能计算(HPC)、数据中心和云计算环境设计,就像给服务器之间搭建了多条高速公路,让数据可以飞驰而过。 阅读详情

相关推荐

最新版谷歌浏览器Axure插件(免翻墙)

本文介绍了在Chrome浏览器无法直接打开Axure导出HTML文件的解决方法。由于国内网络限制无法访问Chrome商店,需手动下载安装AxureRP扩展插件(提供百度网盘下载链接)。安装步骤包括:1)启用开发者模式;2)拖拽CRX文件或加载解压文件夹;3)勾选"允许访问文件网址"。同时还提示若浏览器版本过低可能无法正常运行,并给出了浏览器升级方法。该教程详细说明了从插件安装到浏览器升级的完整解决方案。

OldCat先生 2973

hdu 5074 Hatsune Miku(2014 鞍山现场赛)

Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 17    Accepted Submission(s): 14 Problem Description Hatsune Miku is

ACway的专栏 786

数字IC时序约束实战:深入解析clock_uncertainty的设置策略与后端影响

本文深入探讨数字IC设计中clock_uncertainty的设置策略及其对后端实现的影响。通过分析时钟不确定度的组成(包括clock_skew、clock_jitter和margin),并结合实际项目经验,详细介绍了在不同设计阶段(综合、布局布线、签核)的动态调整方法。文章还提供了工程化处理参数来源、跨时钟域特殊处理以及优化时序收敛的实用技巧,帮助工程师提升数字IC设计的可靠性和性能。

weixin_29284657的博客 227

HDU 5074 Hatsune Miku 暴力dp

点击打开链接 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 677    Accepted Submission(s): 490 Problem Description

代码改变世界,keep coding。 1171

大模型推理中Prefill与Decode、KV Cache三者说明

Prefill 阶段对输入 Prompt 并行编码,一次性构建KV Cache,属于计算密集型任务。Decode 阶段逐 token 迭代生成,复用KV Cache避免重复计算,属于显存带宽密集型任务。KV Cache是自回归推理的核心基石,用显存换时间,实现两阶段衔接与高效生成。PD 分离通过任务解耦、异构硬件、异步调度、独立批处理,解决传统一体化推理的资源冲突与利用率低下问题,是当前云端大模型推理服务的主流工程优化方向。

a486259的博客 1482

CXL协议-第三章 CXL事务层

CXL.io为I/O设备提供了一个非一致的负载/存储接口。图3-1显示了Flex总线分层层次结构中的位置。事务类型、事务分组格式、基于信用的流量控制、虚拟通道管理和事务排序规则遵循PCIe*定义,详情请参考PCIe基础规范的“事务层规范”章节。本章重点介绍了用于CXL.io的著名的PCIe操作模式或特性。

qq_41305217的博客 2769

hdu5074 Hatsune Miku 2014鞍山现场赛E题 水dp

http://acm.hdu.edu.cn/showproblem.php?pid=5074 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 325    Accepted Submission(s

689

相机图像质量评估标准全解析:MTF、CA、SNR 与色彩偏差的实战理解

图像质量评估是影像系统开发中的核心环节,它直接影响用户视觉体验与终端产品竞争力。本文基于真实的图像调试工程实践,系统讲解主流图像评价指标,包括调制传递函数(MTF)、色差(CA)、信噪比(SNR)与色彩偏差(DeltaE)等关键标准。结合 Imatest 测试流程与实际样张数据,逐项拆解各项指标在实际图像分析中的意义与优化路径,帮助开发者建立完整、量化、工程化的图像质量评估体系。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 2805

hdu5074 Hatsune Miku(简单dp)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5074 题目大意: 给一个m*m的矩阵,有n个数a[i]。然后定义score(i,j)是矩阵第i行第j列的值,i,j分别是a[i]和a[i+1]。现在给出了n个数a[i],如果a[i]是-1,那么就可以把a[i]变成1~n里面的任意一个数。现在问能得到的最大分数是多少。 思路: 简单的d

hahahaha 1006

使用 MATLAB/Simulink + Simscape Electrical 构建一个他励直流电机的启动与制动过程仿真模型

直流电机在工业控制、电动车辆、自动化设备中广泛应用。其中,他励直流电机(Separately Excited DC Motor)因其励磁绕组与电枢绕组分别供电,具有良好的调速性能和启动特性,常用于需要平稳启动和精确控制的场合。在实际应用中,电机的启动过程和制动过程对电网、机械系统以及电机本身都具有重要影响。因此,仿真分析他励直流电机的启动与制动特性,是电机控制设计的重要环节。本文将详细介绍如何使用构建一个他励直流电机的启动与制动过程仿真模型,并通过仿真分析其动态响应。本文详细介绍了如何使用构建一个。

amy_mhd的博客 231

redhawk:STA timing data file解析

我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?STA timing data file分为以下几个部分:• Header• Name Map• Footer这部分报告设计的基本信息,例如文件类型,设计名称,分隔符等。...

m0_61544122的博客 1153

HDU 5074 Hatsune Miku DP

解题思路: 题意为有m种音符,编号1到m,我们要用这m种音符来创造一首带有n个音符的曲子(当然,一种音符可以用多次),假设有两个连续的音符 i ,j ,那么定义score(i,j)为这两个音符的得分,题目中预先给出所有的score(i,j)   1<=i,j<=m, 那么我们创造出的n个音符的曲子的得分为  score( note[i] , note[i+1] ) + score (note

Fighting_Dream 560

AI智能体丨使用Coze一键生成爆款书单视频,3个月内获赞131.1w!(附保姆级教程)

这篇教程详细介绍了如何使用扣子(Coze)平台的AI智能工作流批量制作爆款书单视频。通过自动化流程,只需1-2分钟即可生成45-50秒的书单视频,效率提升近百倍。工作流包含文案生成、音频合成、图片素材获取、视频剪辑等全流程,支持随机生成8本书单、自动提取金句、智能配音等功能。教程提供了完整的操作步骤,包括剪映草稿配置、特效添加等细节,并附体验链接和示例效果。最终生成的视频包含书单展示、金句字幕、背景音乐等元素,适合书单号运营者快速批量产出内容。

李同学Lino的博客 2354

HDU 5074 Hatsune Miku(暴力+DP)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5074 思路:暴力+DP AC代码: #include #include #include #include #include #include #include #include #include #include #include const int inf = 0x3f

Java识堂,一个有干货的微信公众号 603

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

hdu5074 Hatsune Miku dp

hdu5074 Hatsune Miku

u014445884的专栏 419

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu 5074 Hatsune Miku【DP】

Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1495    Accepted Submission(s): 1015 Problem Description Hatsune Miku is

mengxiang000000 1万+

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HDU 5074 Hatsune Miku(简单二维dp)

题目大意:给你一些音符之间的联系,给你一个串,让你求出这个串的最大值。-1的时候可以任意替代,其他情况必须为序列上的数。 解题思路:简单二维dp,分情况处理就可以了啊。 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Su

I am a slow walker, but I never walk backwards! 1082

hdu 5074 Hatsune Miku(dp)

题目连接:hdu 5074 Hatsune Miku 题目大意:给定给一个M∗M的矩阵,以及一个长度为N的数组,每次取G[a[i]][a[i+1]]的值,如果a[i]为-1则可以是任何数,问说最大值。 解题思路:dp[i][j]表示第i个数为j的时候的最优解,如果a[i]不为-1,那么j = a[i],否则枚举j。 #include #include #include usi

不慌不忙、不急不躁 777

HDU 5074 Hatsune Miku(DP)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5074 题目大意:给定一个长度为n的序列c[i],该序列为一个乐谱。我们的任务是要给这个序列补上音符。c[i]的数值有两种情况:-1、不是-1。不是-1的这个位置的音符已经确定,不能再更改。是-1的这个位置音符可以任意选择。可以选择的音符有m种,编号为1-m。              当乐谱序列

cxhscst2 352

HDU 5074 Hatsune Miku 【dp思维】

传送门 //题意: 给一个m*m的矩阵, 有n个数a[i]. 然后定义score(i,j)是矩阵第i行第j列的值, i, j分别是a[i]和a[i+1]. 现在给出了n个数a[i], 如果a[i]是-1, 那么就可以把a[i]变成1~n里面的任意一个数。现在问能得到的最大分数是多少.//思路: 简单的dp. 设dp[i][j]代表前i个数最后一个为j时的最大分数 所以只需要分两种情况讨论下就可以

Anxdada -- 我等风来也等你 591

hdu 5074 Hatsune Miku 简单dp

题意:给出m*m的分值表和一个序列(其中有些位置待填),求总分值的最大值。总分值=序列中相邻元素的分值之和。解法:dp[i][x]表示考虑了前i个序列且最后一个为x的最优值。代码:#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #inc

便纵有千种风情 466

HDU 5074 Hatsune Miku (线性dp)

HDU 5074 Hatsune Miku (线性dp) 2014acm鞍山区域赛

Tc的专栏 1565

Hatsune Miku HDU-5074 DP

Hatsune Miku code #include <bits/stdc++.h> using namespace std; int sco[110][110]; int idx[110]; int dp[110][110]; void solve() { int o; cin >> o; while(o --) { int n, m; cin >> n >> m; for(int i =

qq_46173805的博客 1241

hdu5074Hatsune Miku dp水题

#include #include #include using namespace std ; const int maxn = 110 ; int dp[maxn][maxn] ; int ss[maxn][maxn] ; int a[maxn] ; int main() { int t ; scanf("%d" , &t) ; while(t--) {

ijbuhv的专栏 538

hdu 5074 Hatsune Miku DP题目

题目传送门http://acm.hdu.edu.cn/showproblem.php?pid=5074 $dp[i][j] =$ 表示数列前$i$个数以$j$结尾的最大分数 $dp[i][j] = -1$ 表示不可能取到。 当$b[i] = -1$ 时: $$dp[i][j] = \max(dp[i][j],dp[i-1][k] + scores[k][j])$$ $$(...

weixin_30566149的博客 136

HDU 5074 Hatsune Miku(DP)

Problem Description Hatsune Miku is a popular virtual singer. It is very popular in both Japan and China. Basically it is a computer software that allows you to compose a song on your own usi...

weixin_30345055的博客 67
上一篇: HDU 2087 剪花布条(kmp)
下一篇: POJ 2528 Mayor's posters(线段树+离散化)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值