每个花按序号顺序放到窗口,不同窗口可有不同观赏值,所有花都要放上去,求最大观赏值和花的位置。

分析

dp,dp[i][j]表示前i朵花最后一朵在j位置的最大总观赏值。

dp[i][j]=max(dp[i-1][k]+f[i][j])

代码

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=;
int n,w,ans=-;
int dp[N][N],f[N][N],last[N][N],ansp[N];
int main()
{ scanf("%d%d",&n,&w);
for(int i=; i<=n; i++)
{
for(int j=; j<=w; j++)
{
scanf("%d",&f[i][j]);
}
}
for(int i=; i<=n; i++)
{
for(int j=i; j<=w-n+i; j++)
{
dp[i][j]=dp[i-][i-]+f[i][i];
for(int k=i-; k<j; k++)
{
if(dp[i-][k]+f[i][j]>dp[i][j])
{
dp[i][j]=dp[i-][k]+f[i][j];
last[i][j]=k;
}
}
if(i==n && dp[n][j]>ans)
{
ans=dp[n][j];
ansp[n]=j;
}
}
}
int k=ansp[n];
for(int i=n; i>; i--)
{
k=last[i][k];
ansp[i-]=k;
}
printf("%d\n",ans);
for(int i=; i<=n; i++)
printf("%d ",ansp[i]);
return ;
}

【SGU 104】Little shop of flowers的更多相关文章

  1. 题解 【POJ1157】LITTLE SHOP OF FLOWERS

    先把题目意思说一下: 你有F束花,编号为\(1\)~\(F\)(\(1<=F<=100\)),\(V\)个花瓶,编号为\(1\) ~\(V\)(\(1<=V<=100\)), ...

  2. 【SGU 390】Tickets (数位DP)

    Tickets   Description Conductor is quite a boring profession, as all you have to do is just to sell ...

  3. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

  4. 【UOJ #104】【APIO 2014】Split the sequence

    http://uoj.ac/problem/104 此题的重点是答案只与切割的最终形态有关,与切割顺序无关. 设\(f(i,j)\)表示前\(i\)个元素切成\(j\)个能产生的最大贡献. \(f(i ...

  5. 【SPOJ 104】HIGH - Highways (高斯消元)

    题目描述 In some countries building highways takes a lot of time- Maybe that's because there are many po ...

  6. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  7. SGU 104. Little shop of flowers (DP)

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB PROBLEM Yo ...

  8. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【Codeforces 258E】 Devu and Flowers

    [题目链接] http://codeforces.com/contest/451/problem/E [算法] 容斥原理 [代码] #include<bits/stdc++.h> usin ...

随机推荐

  1. 数据结构Java实现02----线性表与顺序表

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  2. Unity-WIKI 之 DebugConsole

    功能预览 使用说明 1.把 DebugConsole.cs 放在 Standard Assets 目录下(重要) 2.如果你想修改 DebugConsole的一些参数,把DebugConsole.cs ...

  3. mongoVUE1.5.3 破解方法

    MongoVUE是个免费软件,但超过15天后功能受限.可以通过删除以下注册表项来解除限制: [HKEY_CURRENT_USER\Software\Classes\CLSID\{B1159E65-82 ...

  4. R 语言assign 和get 函数用法

    assign函数在循环时候,给变量赋值,算是比较方便 1.给变量赋值 for (i in 1:(length(rowSeq)-1)){ assign(paste("nginx_server_ ...

  5. Javascript中的delete

    一.问题的提出 我们先来看看下面几段代码,要注意的是,以下代码不要在浏览器的开发者工具(如FireBug.Chrome Developer tool)中运行,原因后面会说明: 为什么我们可以删除对象的 ...

  6. C语言 结构体中的成员域偏移量

    //C语言中结构体中的成员域偏移量 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> # ...

  7. Windows7+VS2012下OpenGL 4的环境配置

    系统环境 Windows 7 Ultimate x64,Visual Studio Ultimate 2012 Update 4,和一块支持OpenGL 4.x的显卡. 准备工作 首先用GPU Cap ...

  8. windows下git bash显示中文

    1.C:\Program Files\Git\etc\git-completion.bash: alias ls='ls --show-control-chars --color=auto' 说明:使 ...

  9. linux实践——ELF分析

    一.ELF的部分结构定义 elf header(定义在/usr/include/elf.h)//64位的系统ELF文件头包括以下两个部分 #define EI_NIDENT (16) typedef ...

  10. 技能获取与C语言学习情况

    你有什么技能比大多人(超过90%以上)更好? 仔细回想了一下自己到目前为止的学习生涯,好像真的没有什么技能能够比90%以上的人好. 初中高中学过很多东西,但是能够算得上专精的却着实没有.小学参加过计算 ...