UESTC 1217 The Battle of Chibi
dp+树状数组优化。
dp[i][j]表示以a[i]结尾,最长上升序列长度为j的方案数。dp[i][j]=sum{dp[k][j-1]} 其中k<i&&a[k]<a[i]。 离散化后,可以用1000个树状数组维护。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi = acos(-1.0), eps = 1e-;
void File()
{
freopen("D:\\in.txt", "r", stdin);
freopen("D:\\out.txt", "w", stdout);
}
inline int read()
{
char c = getchar(); while (!isdigit(c)) c = getchar();
int x = ;
while (isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} int mod=;
const int maxn=;
int a[maxn],b[maxn],c[maxn][maxn],dp[maxn][maxn],ans;
int T,n,m; int lowbit(int x) { return x&(-x); }
int sum(int r,int p) { int res=; for(int i=p;i>;i=i-lowbit(i)) res=(res+c[r][i])%mod; return res; }
void update(int r,int p,int v) { for(int i=p;i<=;i=i+lowbit(i)) c[r][i]=(c[r][i]+v)%mod; } int main()
{
scanf("%d",&T); int cas=;
while(T--)
{
scanf("%d%d",&n,&m); memset(c,,sizeof c); ans=;
for(int i=;i<=n;i++) scanf("%d",&a[i]),b[i-]=a[i];
sort(b, b + n); int sz = unique(b, b + n) - b;
for(int i=;i<=n;i++) a[i]=lower_bound(b, b + sz, a[i])-b+;
for(int i=;i<=n;i++)
{
dp[i][]=; update(,a[i],dp[i][]);
for(int j=;j<=m;j++) { dp[i][j]=sum(j-,a[i]-); update(j,a[i],dp[i][j]); }
}
for(int i=;i<=n;i++) ans=(ans+dp[i][m])%mod;
printf("Case #%d: %d\n",cas++,ans);
}
return ;
}
UESTC 1217 The Battle of Chibi的更多相关文章
- ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) = ...
- DP+BIT(优化复杂度) UESTC 1217 The Battle of Chibi
题目传送门 题意:问n长度的序列,找出长度m的上升子序列的方案数. 分析:这个问题就是问:dp[i][j] = sum (dp[i-1][k]) (1 <= k <= n, a[k] &l ...
- CDOJ 1217 The Battle of Chibi
The Battle of Chibi Time Limit: 6000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...
- The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- 2015南阳CCPC C - The Battle of Chibi DP
C - The Battle of Chibi Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Cao Cao made up a ...
- hdu5542 The Battle of Chibi【树状数组】【离散化】
The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- HDU - 5542 The Battle of Chibi(LIS+树状数组优化)
The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...
- 2015南阳CCPC C - The Battle of Chibi DP树状数组优化
C - The Battle of Chibi Description Cao Cao made up a big army and was going to invade the whole Sou ...
随机推荐
- action 耦合方式
//ActionContext 方式 package com.hanqi.action; import java.util.Map; import com.opensymphony.xwork2.Ac ...
- wcf测试工具
WCF测试工具-WcfStorm WCF测试工具-WcfStorm http://www.wcfstorm.com/wcf/home.aspx WcfStorm is a dead-simple, ...
- timeit模块 与 time模块,计时的区别
time 模块,理解容易 import time time_start = time.time() time_end = time.time() time_use = time_end - time ...
- for i in xrange(0,5)使用过程中遇到的问题
文件中共有4行内容. fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0, ...
- sql-yog
sqlyog及类似工具的使用 #建表 #索引 #联合索引 #前缀索引 #表注释 #sql语句
- 配置Windows为NTP服务器
建议使用 ntpd for windows,这是一个ntp的windows版,操作和linux相似 下载:https://www.meinbergglobal.com/english/sw/ntp.h ...
- Latex问题收集
1. Latex中的空格 两个quad空格 a \qquad b 两个m的宽度 quad空格 a \quad b 一个m的宽度 大空格 a\ b 1/3m宽度 中等空格 a\;b 2/7m宽度 小空格 ...
- Char device registration
The kernel uses structures of type struct cdev to represent char devices internally. Include <lin ...
- php基础(六)Include
本文内容来自http://www.w3school.com.cn/php/php_file.asp 服务器端包含 (SSI) 用于创建可在多个页面重复使用的函数.页眉.页脚或元素. include ( ...
- ggplot2 geom相关设置—分布图
分布在R中应该算是个比较重要的内容,而通过画图来展示数据的分布,可以更直观的让我们了解数据的分布情况 直方图 geom_histogram(mapping = NULL, data = NULL, s ...