CDOJ 1217 The Battle of Chibi【树状数组+dp】
来源:互联网 发布:android权威指南 源码 编辑:程序博客网 时间:2024/06/05 00:41
题目链接:
http://acm.uestc.edu.cn/#/problem/show/1217
题意:
给定长度为n的序列,求长度为m的严格上升子序列个数。
分析:
dp
状态转移方程:枚举长度和他前面的比他小的元素进行状态的转移,时间复杂度
采用树状数组进行优化,我们就可以
由于
/*--I AM SUPER ROBBISH--Created by jiangyuzhu--2016/5/19*/#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;#define pr(x) cout << #x << ": " << x << " "#define pl(x) cout << #x << ": " << x << endl;#define sa(x) scanf("%d",&(x))#define sal(x) scanf("%lld",&(x))#define mdzz cout<<"mdzz"<<endl;const int maxn = 1e3 + 5, maxm = 5, mod = 1e9 + 7, oo = 0x3f3f3f3f;int bit[maxn][maxn];int dp[maxn][maxn];int nn;int a[maxn], na[maxn];int maxa;void add(int i, int len, int x){ while(i <= maxa){ bit[i][len] = (x + bit[i][len]) % mod; i += i & -i; }}int sum(int i, int len){ int ans = 0; while(i){ ans = (ans + bit[i][len]) % mod; i -= i &-i; } return ans % mod;}int main (void){ int t;sa(t); int c = 1; while(t--){ int n, m;sa(n);sa(m); for(int i = 0; i < n; i++){ sa(a[i]); na[i] = a[i]; } sort(na, na + n); nn = unique(na, na + n) - na; maxa = 0; for(int i = 0; i < n; i++){ a[i] = lower_bound(na, na + nn, a[i]) - na; a[i]++; maxa = max(maxa, a[i]); } memset(dp, 0, sizeof(dp)); memset(bit, 0, sizeof(bit)); for(int i = 0; i < n; i++){ add(a[i], 1, 1); dp[i][1] = 1; for(int j = 2; j <= m; j++){ dp[i][j] = sum(a[i] - 1, j - 1); add(a[i], j, dp[i][j]); if(!dp[i][j]) break; } } printf("Case #%d: %d\n", c++, sum(maxa, m)); } return 0;}/*1005 21 1 1 2 29 31 1 1 2 2 2 3 3 33 21 2 33 23 2 1*/
0 0
- CDOJ 1217 The Battle of Chibi【树状数组+dp】
- HDU-5542-The Battle of Chibi【树状数组+dp】
- HDU 5542 The Battle of Chibi(DP+树状数组)
- HDU 5542 The Battle of Chibi(树状数组+dp)
- HDU 5542 The Battle of Chibi 树状数组+dp+优化
- 【HUD】5542 The Battle of Chibi 【dp+树状数组】
- HDU 5542 The Battle of Chibi(dp+树状数组)
- 南阳ccpc C题 The Battle of Chibi(树状数组优化+dp)
- 2015 南阳 CCPC hdu 5542 The Battle of Chibi(DP+树状数组优化+离散化)
- hdu 5542 The Battle of Chibi(DP+树状数组+离散化)
- HDU 5542 The Battle of Chibi——树状数组 + dp
- UESTC 1217 The Battle of Chibi (树状数组 + 离散化 + 动态规划)
- HDU5542 The Battle of Chibi (DP)
- HDU5542 The Battle of Chibi【DP】
- HDU5542-The Battle of Chibi
- The Battle of Chibi HDU
- hdu 5542 The Battle of Chibi
- HDU 5542 The Battle of Chibi
- 利用xtrabackup和binlog增量恢复时提示表记录不存在案例
- Java像素级的操作
- 分类算法(3) ---- 感知机(PLA)
- 从Excel文件中导入数据到SQL Server 2012
- Mantis 问题管理系统
- CDOJ 1217 The Battle of Chibi【树状数组+dp】
- SpringMVC学习系列-后记 解决GET请求时中文乱码的问题
- 教你学会使用Git和远程代码库
- 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}。由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2。如果不存在
- oc----巧用storyboard/xib的小技巧,Preview~预览,提高效率
- Windows 7下安装使用Sublime Text 3
- Android中bool的使用
- Shell正则表达式与通配符
- Android 属性动画(Property Animation) 完全解析 (上)