题目描述

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 <ctype.h>
#include <cstdio>
void read (int &x)
{
x=;bool f=;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') f=;
ch=getchar();
}
while(isdigit(ch))
{
x=x*+ch-'';
ch=getchar();
}
x=f?(~x)+:x;
}
int n,A[],sum[],dp[];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
read(n);
for(int i=;i<=n;i++)
{
read(A[i]);sum[i]=sum[i-]+A[i];
if(sum[i]>=) dp[i]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<i;j++)
if(dp[j]>&&sum[i]-sum[j]>=) dp[i]=max(dp[i],dp[j]+);
}
if(!dp[n]) printf("Impossible");
else printf("%d",dp[n]);
return ;
}

洛谷 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. 洛谷 1569 [USACO11FEB]属牛的抗议

    [题解] 非常显然的DP,f[i]表示到第i个位置最多分成几组,f[i]=Max(f[i],f[j]+1) (j<i,sum[j]<=sum[i]) #include<cstdio& ...

  3. P1569 [USACO11FEB]属牛的抗议

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

  4. 题解【洛谷P2863】 [USACO06JAN]牛的舞会The Cow Prom

    题面 题解 \(Tarjan\)板子题. 统计出大小大于\(1\)的强连通分量数量输出即可. 代码 #include <iostream> #include <cstdio> ...

  5. 洛谷P1569属牛的抗议 超级强力无敌弱化版

    P1569 [USACO11FEB]属牛的抗议Generic Cow Prote- 题目描述 约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动.第i头奶牛的理智度 为Ai,Ai可能是负数.约 ...

  6. 洛谷P1522 [USACO2.4]牛的旅行 Cow Tours

    洛谷P1522 [USACO2.4]牛的旅行 Cow Tours 题意: 给出一些牧区的坐标,以及一个用邻接矩阵表示的牧区之间图.如果两个牧区之间有路存在那么这条路的长度就是两个牧区之间的欧几里得距离 ...

  7. USACO 奶牛抗议 Generic Cow Protests

    USACO 奶牛抗议 Generic Cow Protests Description 约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动.第i头奶牛的理智度 为Ai,Ai可能是负数.约翰希望 ...

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

    P1821 [USACO07FEB]银牛派对Silver Cow Party 题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  9. 洛谷 P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat…(树规)

    题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...

随机推荐

  1. 通过查询数据库中的数据匹配在页面上:(set单条数据属性是在页面上的显示与foreach的不同) 通过ID修改提取位置表信息

    ACTION   OpenModifyExtractPositionById // set单条数据属性 /* * 通过ID修改提取位置表信息 */ public String OpenModifyEx ...

  2. 并不对劲的bzoj3626:loj2558:p4211:[LNOI2014]LCA

    题目大意 有一棵有\(n\)(\(n\leq5*10^4\))个点的树,\(q\)(\(q\leq5*10^4\))次询问,每次给出\(l,r,x\)表示询问所有编号在\([l,r]\)的点与点\(x ...

  3. sizeof注意

    1.sizeof用于获取非托管类型的大小(以字节为单位). 非托管类型包括下表列出的内置类型以及以下类型: 枚举类型 指针类型 用户定义的结构,不包含任何属于引用类型的字段或属性     struct ...

  4. redis info 参数说明

    原文: redis info 参数说明 redis 127.0.0.1:6381> info redis_version:2.4.16 # Redis 的版本redis_git_sha1:000 ...

  5. linq to EF分组查询 group by 的使用

    第一种:查询表达式语法: IQueryable<EnrollmentDateGroup> data = from student in db.Students group student ...

  6. P5106 dkw的lcm

    传送门 终于A了--细节真多-- 首先我们发现这是个连乘,而且\(\phi\)是个积性函数,所以我们可以考虑不同的质因子以及它的不同次数的贡献.简单来说就是把每一次的\(\phi(lcm(i_1,i_ ...

  7. P3158 [CQOI2011]放棋子

    传送门 题解(因为公式太多懒得自己抄写一遍了--) //minamoto #include<bits/stdc++.h> #define ll long long #define R re ...

  8. iOS 上传APP到AppStore 卡在 Authenticating with the iTunes store 提示

    上传APP的时候,遇到了问题,一直卡在Authenticating with the iTunes store提示这里, 解决办法:在Application Loader里面登录需要上传APP的开发者 ...

  9. C++入门知识点总结

    阅读目录 1 C++中的命名空间 C++中使用命名空间来解决在相同文件或范围的同名变量问题,示例程序如下: #include <iostream> using namespace std; ...

  10. bryce1010专题训练——线段树习题汇总

    一.区间查询,无单点更新 hdu2795 Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 ...