P1569 [USACO11FEB]属牛的抗议Generic Cow Prote…

题目描述

Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another one of their strange protests, so each cow i is holding up a sign with an integer A_i (-10,000 <= A_i <= 10,000).

FJ knows the mob of cows will behave if they are properly grouped and thus would like to arrange the cows into one or more contiguous groups so that every cow is in exactly one group and that every group has a nonnegative sum.

Help him count the number of ways he can do this, modulo 1,000,000,009.

By way of example, if N = 4 and the cows' signs are 2, 3, -3, and 1, then the following are the only four valid ways of arranging the cows:

(2 3 -3 1) (2 3 -3) (1) (2) (3 -3 1) (2) (3 -3) (1) Note that this example demonstrates the rule for counting different orders of the arrangements. 

约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动。第i头奶牛的理智度 为Ai,Ai可能是负数。约翰希望奶牛在抗议时保持理性,为此,他打算将所有的奶牛隔离成 若干个小组,每个小组内的奶牛的理智度总和都要大于零。由于奶牛是按直线排列的,所以 一个小组内的奶牛位置必须是连续的。 请帮助约翰计算一下,最多分成几组。

输入输出格式

输入格式:

第1行包含1个数N,代表奶牛的数目。

第2至N+1行每行1个整数Ai。

输出格式:

输出文件有且仅有一行,包含1个整数即为最多组数。

若无法满足分组条件,则输出Impossible。

输入输出样例

输入样例#1: 复制

4
2
3
-3
1

输出样例#1: 复制

3

说明

【数据规模和约定】

30%的数据满足N≤20。

100%的数据满足N≤1000,|Ai|≤100000。

思路:区间动规。

#include <iostream>
#include <string>
#define maxn 1005
using namespace std;
int n;
int a[maxn];
int dp[maxn],sum[maxn];
int main(){cin>>n;for(int i=1;i<=n;++i){cin>>a[i];sum[i]=sum[i-1]+a[i];if(sum[i]>=0) dp[i]=1;}for(int i=1;i<=n;++i)for(int j=1;j<i;++j)if(dp[j]>0&&sum[i]-sum[j]>=0)dp[i]=max(dp[i],dp[j]+1);if(!dp[n])    cout<<"Impossible"<<endl;else    cout<<dp[n]<<endl;
}

转载于:https://www.cnblogs.com/cangT-Tlan/p/7967121.html

洛谷 P1569 [USACO11FEB]属牛的抗议Generic Cow Prote…相关推荐

  1. 洛谷P1569 [USACO11FEB]属牛的抗议Generic Cow Prote…

    题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cow ...

  2. P1569 [USACO11FEB]属牛的抗议Generic Cow Prote…

    P1569 [USACO11FEB]属牛的抗议Generic Cow Prote- 题目描述 Farmer John's N (1 <= N <= 100,000) cows are li ...

  3. 信息学奥赛一本通 1343:【例4-2】牛的旅行 | 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours

    [题目链接] ybt 1343:[例4-2]牛的旅行 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours [题目考点] 1. 图论 最短路径 Floyd算法 Floyd算法时间复杂度 ...

  4. 洛谷 P3014 [USACO11FEB]牛线Cow Line

    P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) ...

  5. 洛谷 P1821 [USACO07FEB]银牛派对Silver Cow Party

    题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...

  6. 洛谷P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  7. 洛谷P1821 [USACO07FEB]银牛派对Silver Cow Party

    题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...

  8. 洛谷——P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

  9. 洛谷 P2862 [USACO06JAN]把牛Corral the Cows

    P2862 [USACO06JAN]把牛Corral the Cows 题目描述 Farmer John wishes to build a corral for his cows. Being fi ...

最新文章

  1. unity3d EasyTouch滑动屏幕移动相机观看场景
  2. IIS启动时出现0x8ffe2740的错误
  3. 4kyu Twice linear
  4. C#用xpath查找某节点
  5. Object-C学习代码【简单的Car程序】
  6. 20145302张薇《Java程序设计》实验三报告
  7. 2010 北大软件及微电子学院 《软件实现技术》小组博客
  8. Java写js的Ajax代码_用JS写的一个Ajax库(实例代码)
  9. php 快递100接口
  10. cdma特有效应_[多选] 相对于IS-95A,下列特征哪些是CDMA20001x系统所特有的().
  11. Unity Shader数学基础——笛卡尔坐标,点,矢量
  12. 1483套求职个人简历PPT模板免费下载网址
  13. 《人性的弱点》【美】戴尔 卡耐基 读书笔记
  14. vue 项目在index.html页面直接引入jq库,报错$ is not defined解决方案
  15. emuelec 镜像太大无法写入U盘解决方法
  16. 创建手工凭证实现分录中原币=0本位币<>0的效果-FBB1
  17. 东软集团收购软件外包商大连华信
  18. knife4j的使用
  19. PowerPoint如何找回隐藏的iSlide设计工具
  20. Windows App开发之开发准备

热门文章

  1. Share 很喜欢的派大星图片
  2. from vision import VisionDataset报错
  3. 初学Java常用设计模式之——工厂模式
  4. 一款java的篮球游戏_NBA-BASKETBALL 一个非常有趣的nba 篮球游戏 简单操作容易上手代码值得学习 Game Program 238万源代码下载- www.pudn.com...
  5. 地图标绘软件_如何制作专题地图(设计、规划、测绘制作图斑)标绘使用详解...
  6. oracle lag使用情景,lag函数用法
  7. SAP部署SSL数字证书
  8. 通过强化学习和官方API制作《星露谷物语》的自动钓鱼mod
  9. 爱奇艺逗芽表情搜索分析与实践
  10. 制作STG游戏的初步构思