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

分析

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. 2014 Super Training #8 B Consecutive Blocks --排序+贪心

    当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了. 解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241 其实就 ...

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

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

  3. Android数据存储(一)----SharedPreferences详解

    一.Android数据的存储方式: Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File:此外还有一种网络存储 ...

  4. DragRigidbody2D

    组件源码 using UnityEngine; using System.Collections; //This script allows to drag rigidbody2D elements ...

  5. java8-2 多态的概述

    1.多态:同一个对象(事物),在不同时刻体现出来的不同状态. 举例: 猫是猫,猫是动物. 水(液体,固体,气态). 多态的前提: A:要有继承关系. B:要有方法重写. 其实没有也是可以的,但是如果没 ...

  6. ASP.NET 里的 JSON操作

    最近项目中需要用到 JSON操作,google了一下 找到了几个比较好的操作方法.... 一 .使用 mircosoft 提供的 .NET Framework 自带的 json操作方法 1. 使用Ja ...

  7. HYSBZ 2145 悄悄话

    2145: 悄悄话 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 271  Solved: 104[Submit][Status][Discuss] ...

  8. 09Spring_AOP介绍和java本身的动态代理以及cglib代理

    Aspect Oriented Programming 面向切面编程 1. 业界 AOP 实际上 OOP (面向对象编程 ) 延伸 ----  OOP编程语言. AOP设计思想,下面给出一张AOP的设 ...

  9. Android开发eclipse运行程序时报timeout的解决方法

    eclipse开发Android程序时,忽然莫名其妙报这个错,之前还好好的.忽然就不行了. Failed to install xxx.apk on device~~~: timeout 尝试过手机里 ...

  10. tee命令

    tee命令 http://liubin.blog.51cto.com/282313/131298 https://en.wikipedia.org/wiki/Tee_(command)