hdu-5568SUM (dp)
2024-09-05 22:49:16
sequence2
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 677 Accepted Submission(s): 244
Problem Description
Given an integer array bi with a length of n, please tell me how many exactly different increasing subsequences.
P.S. A subsequence bai(1≤i≤k) is an increasing subsequence of sequence bi(1≤i≤n) if and only if 1≤a1<a2<...<ak≤n and ba1<ba2<...<bak.
Two sequences ai and bi is exactly different if and only if there exist at least one i and ai≠bi.
P.S. A subsequence bai(1≤i≤k) is an increasing subsequence of sequence bi(1≤i≤n) if and only if 1≤a1<a2<...<ak≤n and ba1<ba2<...<bak.
Two sequences ai and bi is exactly different if and only if there exist at least one i and ai≠bi.
Input
Several test cases(about 5)
For each cases, first come 2 integers, n,k(1≤n≤100,1≤k≤n)
Then follows n integers ai(0≤ai≤109)
For each cases, first come 2 integers, n,k(1≤n≤100,1≤k≤n)
Then follows n integers ai(0≤ai≤109)
Output
For each cases, please output an integer in a line as the answer.
Sample Input
3 2
1 2 2
3 2
1 2 3
1 2 2
3 2
1 2 3
Sample Output
2
3
3
Source
Recommend
hujie
Statistic | Submit | Discuss | Note
令{A}_{i}=f({A}_{i})-{A}_{i}Ai=f(Ai)−Ai,然后求一遍最大连续子序列和就能知道最多能增加的值。
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<stdlib.h>
5 #include<vector>
6 #include<queue>
7 #include<cstdio>
8 #include<string.h>
9 typedef long long ll;
10 using namespace std;
11 ll a[100005];
12 ll b[100005];
13
14 int main(void)
15 {
16 ll n,i,j,k,p,q;
17
18 while(scanf("%lld",&n)!=EOF)
19 { ll tt=0;
20 for(i=0; i<n; i++)
21 {
22 scanf("%lld",&a[i]);
23 tt+=a[i];
24 }
25 for(i=0; i<n; i++)
26 {
27 b[i]=(1890*a[i]+143)%10007-a[i];
28 }
29 ll sum=0;
30 ll cnt=b[0];
31 if(sum<cnt)
32 {
33 sum=cnt;
34 }
35 for(i=1; i<n; i++)
36 {
37 if(b[i-1]>=0)
38 {
39 b[i]+=b[i-1];
40
41 }
42 if(sum<b[i])
43 {
44 sum=b[i];
45 }
46 }
47 if(sum<0)
48 {
49 sum=0;
50 }
51 printf("%d\n",sum+tt);
52 }
53 return 0;
54
55
56 }
最新文章
- ---bind 配置
- select 嵌套
- 发短信的简单实现——C#版
- ActiveMQ的使用笔记(基本实现原理)
- 改变tableView索引颜色
- Java学习-012-文件删除实例及源代码
- android 学习随笔二十八(应用小知识点小结 )
- ubuntu 14.04 apache maven 安装
- 最短路径—Dijkstra算法和Floyd算法【转】
- 基于 HTML5 的数据存储
- geoserver扫盲 openlayers相关
- 【狼】unity3d collision获取碰撞的点的位置
- javamail发送二进制流附件的问题
- 通过Manifest的配置信息实现页面跳转,及总结
- Hbase shell 中能否通过filter实现的高级查询
- (原创)用JAX-WS+Spring实现简单soap规范的webservice
- svn服务器的搭建与使用一
- Tcl与Design Compiler (五)——综合库(时序库)和DC的设计对象
- 封装、property特性及绑定与非绑定方法
- 学习下知然网友写的taskqueue