【POJ】poj 1157 (DP)

How to Hack Like a Pornstar_2017.pdf.zip How to Hack Like a Pornstar,一本17年流传于国外论坛的介绍渗透测试的书籍,不要被书名迷惑 立即下载

 

Description

You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers. 

Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0. 

 

V A S E S

1

2

3

4

5

Bunches

1 (azaleas)

723-5-2416

2 (begonias)

521-41023

3 (carnations)

-21

5-4-2020


According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4. 

To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers. If more than one arrangement has the maximal sum value, any one of them will be acceptable. You have to produce exactly one arrangement. 

Input

  • The first line contains two numbers: F, V.
  • The following F lines: Each of these lines contains V integers, so that Aij is given as the jth number on the (i+1)st line of the input file.

 


  • 1 <= F <= 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F. 
  • F <= V <= 100 where V is the number of vases. 
  • -50 <= Aij <= 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j.

Output

The first line will contain the sum of aesthetic values for your arrangement.

Sample Input

3 5
7 23 -5 -24 16
5 21 -4 10 23
-21 5 -4 -20 20

Sample Output

53

 

这个题目是一个动态规划的问题,先定义一个二维数组,表示第i束花插在第j个花瓶上的最大价值,那么就可以得到状态方程

 

f [ i ] [ j ] = for ( k = i ,k < j ) max ( f [ i ] [ j ], maxvaule [ i - 1 ] [ k ] + value [ i ] [ j ] ; 在最后扫描数组最后一行可以得到最佳结果

代码如下:

 

#include<iostream>
#include<cstring>
using namespace std;
int flower,vase;
int aesthetic[105][105];
int maxaes[105][105];/**表示在第i个花放第j个位置的最大的美观程度*/
int main()
{
    while ( cin >> flower >> vase )
    {
        for ( int i = 0; i < flower; i++ )
        {
            for ( int j = 0; j < vase; j++ )
            {
                cin >> aesthetic[i][j];
            }
        }
        for ( int i = 0; i < flower; i++ )
        {
            for ( int j = i; j < vase; j++ )
            {
                if ( i == 0)
                    maxaes[i][j] = aesthetic[i][j];/**如果是第一个花的话就是输入的美观值*/
                else
                {
                    for ( int k = i - 1; k < j; k++ )
                    {
                        if ( maxaes[i][j] < maxaes[ i - 1 ][ k ] + aesthetic[i][j] )/**可以采用01滚动,可以节约空间*/
                            maxaes[i][j] = maxaes[ i - 1 ][ k ] + aesthetic[i][j];
                    }
                }
            }
        }
        int ans = -10000;
        for ( int i = vase - flower; i < vase; i++ )
        {
            if ( ans <  maxaes[ flower - 1 ][ i ] )/**找出插入最后一朵花的最大值*/
                ans =  maxaes[ flower - 1 ][ i ];
        }
        cout << ans << endl;
    }
}

 

 

 

 

 

 

 

 

Autosar结合simulink的汽车应用层软件开发实例 本文基于汽车应用开发案例,并结合Autosar相关知识,生成具有Autosar标准的汽车应用层开发代码,以供学习和参考。以上就是本篇内容,主要是利用Simulink创建Autosar接口并进行端口映射的方法。 阅读详情

相关推荐

Simulink/Requirements Toolbox 学习(一):概述

编写、导入、导出需求并使需求正式化;两种创建需求的模块:需求编辑器、需求透视;描述需求的方式:文本、图像和关键字;通过导入和导出需求文件,与第三方需求管理工具(例如 Microsoft Word、Microsoft Excel®、IBM DOORS和 IBM DOORS Next)集成。涉及模块:Requirements Eidtor、Requirements Table等;

855

POJ 1157 LITTLE SHOP OF FLOWERS

LITTLE SHOP OF FLOWERSTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 10554 Accepted: 4890DescriptionYou want to arrange the window of your flower shop

bobten2008的专栏 647

生成式引擎优化(GEO)- 搜索引擎优化

生成式引擎优化(GEO)是针对AI内容生成平台(如ChatGPT)的新型优化策略,旨在提升品牌内容在AI生成答案中的引用率,与传统SEO存在显著差异。GEO通过优化内容权威性、结构化和语义关联,适应AI的RAG技术架构,采用3C原则(可爬性、网络共识、反馈校正)提升内容可见性。其核心区别在于目标(引用率vs排名)、技术(语义优化vs关键词)及算法透明度(封闭vs开放)。适用场景包括商业决策、行业权威建设及公共知识服务,帮助品牌在AI时代占据信息主导权。

解锁AI流量新红利!🚀 GEO优化(生成引擎优化)助您掌控AI搜索,让AI成为您的品牌最佳代言人! 1399

POJ - 1716 Integer Intervals

Integer Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14913   Accepted: 6310 Description An integer interval [a,b], a Write a program that: fin

哇-WA 的博客 6440

用Cadence IC618仿真双平衡吉尔伯特混频器:从原理图到后仿的完整避坑指南

本文详细介绍了在Cadence IC618环境中设计双平衡吉尔伯特混频器的全流程,包括原理图设计、仿真优化和版图实现。通过实战案例分享,重点解析了设计中的关键技巧和常见问题解决方案,帮助工程师高效完成高性能混频器设计,特别适合射频前端开发人员参考。

weixin_42656416的博客 161

第八届传智杯WPS智能办公能力挑战赛练习题库

本文是关于WPS Office软件操作知识的选择题汇总,内容涵盖WPS文字、表格和演示三大组件的常用功能。主要包括:云文档协同编辑、文本框插入、幻灯片打印设置、数据排序与筛选、函数应用(如SUMIF、COUNT)、动画效果设置、格式刷使用、页眉页脚设置、单元格引用类型等基础操作要点。同时涉及计算机基础概念如二进制、ROM存储器等。题目以单选和多选形式呈现,附带详细答案解析,全面检验用户对WPS办公软件的功能掌握程度和实际操作能力,适用于办公软件技能培训和水平测试。

qq_73044452的博客 1424

20-1-14-Prime-POJ1789

占坑 POJ1789, 2020.1.14日题, 2020.1.15日更新

shen253135371的博客 9453

JEDEC 标准半导体功率循环热阻测试(JESD51 系列)

【代码】JEDEC 标准半导体功率循环热阻测试(JESD51 系列)

专注于前沿技术的探索与实践,热衷于从代码逻辑、架构设计到行业应用等多维度深挖技术本质。期待在技术之路上与你共同成长~ 467

【PAT B1019/A1069】 The Black Hole of Numbers

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in this m

zxc0074869的博客 1万+

SQL基础:HQL之常用的行列转换应用总结

行列转换是数据开发者的基本技能,也是面试重点,在数据开发中处处可见,本文对常见的几种情况进行了总结,包括了多行转多列,多行转单列,多列转多行,单列转多行的几种情况,并给出了解决思路和方法,读者可根据本文给出的思路灵活应对业务中遇到的问题。

石榴姐yyds 1799

第14.5章 高翔博士最新开源框架Lightning-LM源码解读(五):揭秘位姿图优化核心模块,从数学原理到代码实现

本文介绍了Lightning-LM框架中的位姿图优化(PGO)模块实现。该模块通过融合多源定位信息(激光定位、激光里程计、DR等),构建并优化位姿图来获得更精确的位姿估计。 主要内容包括: 模块概况与数据流程:初始化配置→添加PGO帧→分配位姿→优化求解→更新位姿→滑动窗口 16个核心函数详解:从构造函数到边缘化处理,涵盖完整的PGO工作流程 关键技术点:噪声参数设置、优化问题构建、约束添加、异常值处理等 关键数据结构:帧队列管理、顶点和边构建、优化统计信息收集 该PGO模块采用增量式优化方式,支持多种约束

行知SLAM 1215

poj 1157 dp

http://poj.org/problem?id=1157 大意为F束花插入V个瓶子里面,花要按编号插,不同花插入不同的花瓶有不同的美观程度,要求最大的美观程度。 f[i][j]表示第i束花插入前j个瓶子里面。则状态转移函数为f[i][j]=max(f[i-1][j-1]+a[i][j],f[i][j-1]) 因为有两种插法,一:第i束花插入第j个瓶子里面,则为f[i][j]=

Song 752

机器翻译:一文掌握离线翻译库 Argos Translate 的详细使用

Argos Translate是一个开源的离线翻译库,支持多语言互译。它通过独立的翻译包(.argosmodel文件)实现翻译功能,每个包对应特定语言对的翻译任务。安装简单,只需pip安装argostranslate库,并通过命令行或Python API管理翻译包。支持批量处理和长期运行优化性能。对于不支持的语种,可采用桥接翻译或自行训练模型。该库提供CLI工具和Python API,适合集成到各种应用中,还可用于批量文件翻译。主要局限包括缺乏上下文理解、专业领域翻译不精准等。

数据知道的博客 3522

poj1157 dp

题目链接:http://poj.org/problem?id=1157 题目大意:给 F 种花, V 个花瓶(F <= V), a[i][j] 为 i 种花插到第j 个花瓶的价值, 要求第 i + 1 种花要在第 i 种花的右边, 求最大的价值和。 1 #include <iostream> 2 #include <cstdio> 3 #inclu...

weixin_30426065的博客 65

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

DP之数塔模型poj1157

题目:poj1157LITTLE SHOP OF FLOWERS 题意:假设以最美观的方式布置花店的橱窗,有 F 束花,每束花的品种都不一样,同时,至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,并从左到右,从 1 到 V 顺序编号, V  是花瓶的数目,编号为 1 的花瓶在最左边,编号为 V 的花瓶在最右边,花束可以移动,并且每束花用 1 到 F  的整数惟一标识,标识花束

大神养成中..... 2330

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ1157【DP】

题意:每个方格代表一个花瓶,从上到下依次编号1-…这么些花,要求没朵花都插在一个花瓶里,第i朵花插的位置>第i-1朵花插的位置,每个插花的位置有一个美感值,没有插花的位置美感值为0.思路:题目本身不难,瞎打打马上就打好了? 但是要注意几点: 每朵花必须插。 DP过程中注意状态的有效位置,即对于编号第i朵花,它插的位置一定是>=i的呀~Code://#include <bits/stdc++.h

ONE MORE TRY 486

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

poj 1157 经典DP 背包变形

01背包的变形,比较经典的DP花店问题。 状态方程:dp[i][j] = maxcmp(dp[i][j - 1], dp[i - 1][j - 1] + w[i][j]); //============================================================================ // // > File : poj

356

POJ 1157 LITTLE SHOP OF FLOWERS【基础DP】

题意:给出f朵花,v个花瓶,要把花都插到花瓶里去,而且花的顺序不能改变,编号小的在左边,每朵花放到花瓶里都会有一定的价值,问如何放才能产生最大的价值 我们设dp[i][j]表示处理到第i朵花,然后把第i朵花放到第j个花瓶里时所能获得的最大价值; 显然 dp[i][j] = max(dp[i - 1][k]) + val[i][j],其中k< j val[i][j]表示把第i朵花放到第j个花瓶里产生的价值 本题dp状态:

AC_Dreameng 1040

poj 1157 DP

有n种花,m个花瓶,现在需要 把花插到花瓶里,但是花的顺序要保持不变,也就是 说 插入以后 还是要保持 1-n的顺序,中间可以空着,最后要求最大值,因为每种花插到每个花瓶的值不一样。。 思路,dp[j][i]表示 前 i个花瓶已经插了 j种花,那么 dp[j][i]=max(dp[j][i-1],dp[j-1][i-1]+a[j][i]);注意初始化!!! #include #include

qingniaofy的专栏 684

POJ 1157 dp

题意: 给你n个花插到m个花瓶中保证n个花的顺序的情况下如何最大 分析:        dp【i】【j】表示前i种花插入前j种花瓶的最大 dp【i】【j】=max(dp【i-1】【j-1】+cost【i】【j】,dp【i】【j-1】) ACcode: #include #include #include #include #define maxn 105 #include u

MY Blog 474

poj 1157 dp

http://poj.org/problem?id=1157

ACM,再见! 687

POJ1157 花店问题经典DP

题意: 花店摆花,不同的花放进不同的花瓶美观度不同,排在后面的花不能放在排名前的花放入的花瓶的前面的花瓶 要点: 首先注意题意,加入花1放入第2个花瓶,花2就只能放在第3个花瓶或更后面,这样就简单多了,否则估计要用搜索。 这样问题就近似于数字三角形,首先设一个数组dp[i][j]记录当前最大美观度,i代表前i朵花,j表示前j个花瓶。那么就有两种状态,第一种是往右边走,第二种是往右下走,其实

SeasonJoe的博客 723

poj 1157 简单递推dp

题解        花必须插在花瓶中,且编号小的花一定要插在大的之前,那么就可以按照这一顺序进行递推        设d[i][j]为第i束花在j位置时所能得到的最大值        d[i][j]=max(d[i-1][k],d[i][j]) 其中  i        注意数据的初始化        #include #include #include #include #includ

关于完全听不懂神犇在说什么的事 406
上一篇: 【HDU】hdu 2037(贪心)
下一篇: 【POJ】poj 3253 (贪心)
三生石1103
博客等级 码龄12年 16粉丝 87原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值