Super-increasing sequence
来源:互联网 发布:用友怎么初始化数据库 编辑:程序博客网 时间:2024/05/19 15:41
Description
如果一个序列中任意一项都大于前面所有项之和,那么我们就称这个序列为超递增序列。
现在有一个整数序列,你可以将序列中任意相邻的若干项合并成一项,合并之后这项的值为合并前各项的值之和。通过若干次合并,最终一定能得到一个超递增序列,那么得到的超递增序列最多能有多少项呢?
Input
输入数据的第一行包含正整数T (1 <= T <= 500),表示接下来一共有T组测试数据。
每组测试数据的第一行包含一个整数N (1 <= N <= 100000),表示这个整数序列一共有N项。接下来一行包含N个不大于10000的正整数,依次描述了这个序列中各项的值。
至多有10组数据满足N > 1000。
Output
对于每组测试数据,用一行输出一个整数,表示最终得到的超递增序列最多能有多少项。
Sample Input
321 131 2 461 2 4 3 6 5
Sample Output
134
HINT
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define MP make_pair
#define INF (1<<30)
#define PI acos(-1.0)
#define esp 1e-8
const int dx[4]={0,0,0,0};
using namespace std;
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__)
#define LL __int64
#define LLS "%" "I" "6" "4" "d"
#else
#define LL long long
#define LLS "%" "l" "l" "d"
#endif
int main(int argc, char** argv) {
//read;
int t,n,x,sum,cnt,now_sum;
scanf("%d",&t);
while(t--) {
scanf("%d%d",&n,&x);
sum = x;
now_sum = 0;
cnt = 1;
for(int i=1; i<n; i++) {
scanf("%d",&x);
now_sum += x;
if(now_sum > sum) {
sum = sum + now_sum;
now_sum = 0;
cnt ++;
}
}
printf("%d\n",cnt);
}
return 0;
}
- 1203: Super-increasing sequence
- Super-increasing sequence
- CSU 1203 Super-increasing sequence
- CSU - 1203 Super-increasing sequence
- ACM:W: Super-increasing sequence
- CSU 1203 Super-increasing sequence (模拟)
- CSU 1203: Super-increasing sequence 水题
- Increasing Sequence
- 1207: Strictly-increasing sequence
- A. Increasing Sequence
- CSU1207(Strictly-increasing sequence)
- A. Increasing Sequence
- 11A - Increasing Sequence
- Increasing Sub-sequence
- Find longest increasing sequence (LIS)
- CodeForces - 11A Increasing Sequence
- codeforces 11A - Increasing Sequence
- CodeForces 11A - Increasing Sequence
- 4、Linux操作系统之操作篇-硬件相关操作
- C++函数重载(2) - 不能被重载的函数
- 遇到过得基础的sql语句优化
- hihoCoder:1039字符串消除
- GCD使用01
- Super-increasing sequence
- 对于java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I错误解决
- [objective-c]—六十六、基础框架(二十四)文件操作-目录操作
- SVD浅析
- JAVA Timer和TimerTask
- 连号区间数
- Debian下MySQL源码安装
- 适合嵌入式的脚本语言——Lua
- python自学资料资源