hdu5568 sequence2
2015-11-30 11:53
501 查看
思路:题目问的是长度为k的严格上升子序列有多少种。求种数的时候一般会想到大数,也就是简单模拟下加法运算。
// #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <algorithm> #include <iomanip> #include <sstream> #include <string> #include <stack> #include <queue> #include <deque> #include <vector> #include <map> #include <set> #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <limits.h> // #define DEBUG #ifdef DEBUG #define debug(...) printf( __VA_ARGS__ ) #else #define debug(...) #endif #define MEM(x,y) memset(x, y,sizeof x) using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> ii; const int inf = 1 << 30; const int INF = 0x3f3f3f3f; const int MOD = 100000000;//1e8 struct BigInt{ int len, p[110]; BigInt(){ memset(p, 0,sizeof p); len = 0; } BigInt operator +(const BigInt& rhs)const{ BigInt cnt; int t = max(this->len, rhs.len); for (int i = 1;i <= t;++i){ cnt.p[i] += this->p[i] + rhs.p[i]; cnt.p[i+1] += cnt.p[i] / MOD; cnt.p[i] = cnt.p[i] % MOD; } if (cnt.p[t+1]) t++; cnt.len = t; return cnt; } }dp[110][110], ans; int A[110], s, sum, n, k; void print(const BigInt& x){ printf("%d",x.p[x.len]); for (int i = x.len - 1;i >= 1;--i){ printf("%08d", x.p[i]); } printf("\n"); } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); while(scanf("%d%d",&n,&k) != EOF){ memset(dp, 0,sizeof dp); memset(ans.p, 0,sizeof ans.p); ans.len = 0; for (int i = 0;i < n;++i){ scanf("%d",&A[i]); dp[i][1].p[1] = dp[i][1].len = 1; } for (int i = 1;i <= n;++i){ for (int j = 0;j < i;++j){ if (A[i] > A[j]) for (int x = 1;x < n;++x) dp[i][x+1] = dp[i][x+1] + dp[j][x]; } } for (int i = 0;i < n;++i) ans = ans + dp[i][k]; print(ans); } return 0; }
相关文章推荐
- UITableView优化技巧
- UITableView
- Json转换利器Gson之实例二-Gson注解和GsonBuilder
- Lintcode: Unique Paths
- UITableView可编辑状态常用操作
- 自定义UIAlertView第三方类库
- 芒果iOS开发之UITableView详解
- UIview图层的技术
- UIButton中UIEdgeInsetsMake的用法
- Range Sum Query - Immutable
- 基于Spark DataFrame的数据仓库框架
- easyui enableFilter combobox级联 combotree
- 安卓retry error curr request is null报错问题
- easyui-panel
- UGUI 事件
- org.json.JSONException: No value for userPicURL
- UICollectionView详解+实例
- Handler更新主线程UI常用方法
- 解决UICollectionView的cell间距与设置不符问题
- UICollectionView的简单使用