P1569 [USACO11FEB]属牛的抗议
题目描述
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。
输入输出样例
说明
【数据规模和约定】
30%的数据满足N≤20。
100%的数据满足N≤1000,|Ai|≤100000。
// 去吧!皮卡丘! 把AC带回来!
// へ /|
// /\7 ∠_/
// / │ / /
// │ Z _,< / /`ヽ
// │ ヽ / 〉
// Y ` / /
// イ● 、 ● ⊂⊃〈 /
// () へ | \〈
// >ー 、_ ィ │ //
// / へ / ノ<| \\
// ヽ_ノ (_/ │//
// 7 |/
// >―r ̄ ̄`ー―_
//**************************************
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <class T> inline T min(T a, T b, T c, T d) {
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d) {
return max(max(a, b), max(c, d));
}
#define pi acos(-1)
#define mem(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int maxn = 3e5 + ;
// name*******************************
int n;
ll sum[];
int dp[];
int ans=;
// function****************************** //***************************************
int main() {
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin>>n;
For(i,,n){
int x;
cin>>x;
sum[i]=sum[i-]+x;
}
For(i,,n){
For(j,,i-){
if(sum[i]-sum[j]>=&&(j==||dp[j]>))
dp[i]=max(dp[i],dp[j]+);
}
}
if(dp[n])
cout<<dp[n];
else
cout<<"Impossible";
return ;
}
P1569 [USACO11FEB]属牛的抗议的更多相关文章
- 洛谷 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 ...
- 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 ...
- 洛谷 1569 [USACO11FEB]属牛的抗议
[题解] 非常显然的DP,f[i]表示到第i个位置最多分成几组,f[i]=Max(f[i],f[j]+1) (j<i,sum[j]<=sum[i]) #include<cstdio& ...
- 洛谷P1569属牛的抗议 超级强力无敌弱化版
P1569 [USACO11FEB]属牛的抗议Generic Cow Prote- 题目描述 约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动.第i头奶牛的理智度 为Ai,Ai可能是负数.约 ...
- Chinese culture
文房四宝 笔墨纸砚是中国古代文人书房中必备的宝贝,被称为“文房四宝”.用笔墨书写绘画在 中国可追溯到五千年前.秦(前221---前206)时已用不同硬度的毛和竹管制笔:汉代(前206—公元220) ...
- 从Word Embedding到Bert模型—自然语言处理中的预训练技术发展史(转载)
转载 https://zhuanlan.zhihu.com/p/49271699 首发于深度学习前沿笔记 写文章 从Word Embedding到Bert模型—自然语言处理中的预训练技术发展史 张 ...
- [No0000156]天干地支-狗年我懂,戊戌二字怎么来的?
话说,这几年的年份,总能让人联想到历史课本.比如,2014年是甲午马年,是中日甲午战争120周年.而2018年是戊戌狗年,嗯,戊戌变法也过去120年了…… 狗年相信大家都了解,小观前面两期关于反犬旁和 ...
- 鼠标经过,显示悬浮DIV
属牛人的本命佛是虚空藏菩萨.属牛人可佩戴属牛黄玉本命佛来提升财运,黄玉的金黄色代表蒸蒸日上,而“金黄”也就是“黄金”的到(倒)来,象征着富贵与财气,佩戴可以招财招富贵,同时黄玉亦是希望之石,可带来智慧 ...
- 开源前夕先给大家欣赏一下我用C语言开发的云贴吧 网站自动兼容-移动、手机、PC自动兼容云贴吧
开源前夕先给大家欣赏一下我用C语言开发的移动.手机.PC自动兼容云贴吧 - 涨知识属马超懒散,属虎太倔强.十二生肖全了!-转自云寻觅贴吧 转: 涨知识属马超懒散,属虎太倔强.十二生肖全了! -转自云寻 ...
随机推荐
- 关于java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap的错误解决办法
在JavaEE开发中,在把配置文件中的数据或用户表单提交上来的数据,封装在相应JavaBean的对象的对应属性中时:在实际开发中,使用第三方法工具包BeanUtils(commons-beanutil ...
- How To Improve Deep Learning Performance
如何提高深度学习性能 20 Tips, Tricks and Techniques That You Can Use ToFight Overfitting and Get Better Genera ...
- Windows win7下VMware Virtual Ethernet Adapter未识别网络解决方法
win7下VMware Virtual Ethernet Adapter未识别网络解决方法[摘] by:授客 QQ:1033553122 问题描述 win7系统下安装VMware,查看网卡适配器设置, ...
- 非J2EE部署解决方案
根据交银施罗德真实环境已测试通过,此过程可以作为非J2EE部署的典型案例,主要是针对某些对安全性要求较高的解决方案: 基本的实现原理和部分代码如下: 1.客户端访问交银.net系统,由该系统发送 ...
- eval解析json字符串
场景:在springMVC,手动拼接的list,转成本json字符串后,传到前台, 解决:需要解析成json对象,获取对象的属性,动态生成table. 首先,以下是后台准备好的list,list中有两 ...
- Mysql性能监控项及sql语句
推荐一款mysql监控软件MONyog 1.查询缓存: mysql> show variables like '%query_cache%'; 2.缓存在Cache中线程数量thread_cac ...
- FileStream对文本进行读写操作
class FileHelper { /// <summary> /// 检验文件路径是否合法 /// </summary> /// <param name=" ...
- JAVA入门之基础语言
在上一章文章中,读者已经了解了如何搭建Java 开发环境及Java 程序的开发过程.从本篇文章开始讲解Java 的基本语言.这些基本语言的语法和其他一些编程语言相比有些是类似的,但还有很多不同之处,读 ...
- 铁乐学python_Day42_锁和队列
铁乐学python_Day42_锁和队列 例:多个线程抢占资源的情况 from threading import Thread import time def work(): global n tem ...
- 铁乐学python_shelve模块详解
python序列化模块-shelve模块详解 shelve:vt. 将(书等)放置在架子上:搁置,将某事放到一旁不予考虑:将-搁在一边:装搁架于: 个人感觉有点像字典缓存?暂时搁置到一旁的意思? 研究 ...