sequence2

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.

 
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)

 
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
 
Sample Output
2
3
 
题解:我们可以通过dp[i][j]dp[i][j]表示第ii个数,当前这个数为序列中的第jj个数的方案总数。 转移为dp[i][j] = sum{dp[k][j-1]}(k < i, b_k < b_i)dp[i][j]=sumdp[k][j−1](k<i,b​k​​<b​i​​)。 本题需要高精度。
 
//
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0) const int inf=~0u>>;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** #define MAX_L 405 //最大长度,可以修改 class bign
{
public:
int len, s[MAX_L];//数的长度,记录数组
//构造函数
bign();
bign(const char*);
bign(int);
bool sign;//符号 1正数 0负数
string toStr() const;//转化为字符串,主要是便于输出
friend istream& operator>>(istream &,bign &);//重载输入流
friend ostream& operator<<(ostream &,bign &);//重载输出流
//重载复制
bign operator=(const char*);
bign operator=(int);
bign operator=(const string);
//重载各种比较
bool operator>(const bign &) const;
bool operator>=(const bign &) const;
bool operator<(const bign &) const;
bool operator<=(const bign &) const;
bool operator==(const bign &) const;
bool operator!=(const bign &) const;
//重载四则运算
bign operator+(const bign &) const;
bign operator++();
bign operator++(int);
bign operator+=(const bign&);
bign operator-(const bign &) const;
bign operator--();
bign operator--(int);
bign operator-=(const bign&);
bign operator*(const bign &)const;
bign operator*(const int num)const;
bign operator*=(const bign&);
bign operator/(const bign&)const;
bign operator/=(const bign&);
//四则运算的衍生运算
bign operator%(const bign&)const;//取模(余数)
bign factorial()const;//阶乘
bign Sqrt()const;//整数开根(向下取整)
bign pow(const bign&)const;//次方
//一些乱乱的函数
void clean();
~bign();
};
#define max(a,b) a>b ? a : b
#define min(a,b) a<b ? a : b bign::bign()
{
memset(s, , sizeof(s));
len = ;
sign = ;
} bign::bign(const char *num)
{
*this = num;
} bign::bign(int num)
{
*this = num;
} string bign::toStr() const
{
string res;
res = "";
for (int i = ; i < len; i++)
res = (char)(s[i] + '') + res;
if (res == "")
res = "";
if (!sign&&res != "")
res = "-" + res;
return res;
} istream &operator>>(istream &in, bign &num)
{
string str;
in>>str;
num=str;
return in;
} ostream &operator<<(ostream &out, bign &num)
{
out<<num.toStr();
return out;
} bign bign::operator=(const char *num)
{
memset(s, , sizeof(s));
char a[MAX_L] = "";
if (num[] != '-')
strcpy(a, num);
else
for (int i = ; i < strlen(num); i++)
a[i - ] = num[i];
sign = !(num[] == '-');
len = strlen(a);
for (int i = ; i < strlen(a); i++)
s[i] = a[len - i - ] - ;
return *this;
} bign bign::operator=(int num)
{
char temp[MAX_L];
sprintf(temp, "%d", num);
*this = temp;
return *this;
} bign bign::operator=(const string num)
{
const char *tmp;
tmp = num.c_str();
*this = tmp;
return *this;
} bool bign::operator<(const bign &num) const
{
if (sign^num.sign)
return num.sign;
if (len != num.len)
return len < num.len;
for (int i = len - ; i >= ; i--)
if (s[i] != num.s[i])
return sign ? (s[i] < num.s[i]) : (!(s[i] < num.s[i]));
return !sign;
} bool bign::operator>(const bign&num)const
{
return num < *this;
} bool bign::operator<=(const bign&num)const
{
return !(*this>num);
} bool bign::operator>=(const bign&num)const
{
return !(*this<num);
} bool bign::operator!=(const bign&num)const
{
return *this > num || *this < num;
} bool bign::operator==(const bign&num)const
{
return !(num != *this);
} bign bign::operator+(const bign &num) const
{
if (sign^num.sign)
{
bign tmp = sign ? num : *this;
tmp.sign = ;
return sign ? *this - tmp : num - tmp;
}
bign result;
result.len = ;
int temp = ;
for (int i = ; temp || i < (max(len, num.len)); i++)
{
int t = s[i] + num.s[i] + temp;
result.s[result.len++] = t % ;
temp = t / ;
}
result.sign = sign;
return result;
} bign bign::operator++()
{
*this = *this + ;
return *this;
} bign bign::operator++(int)
{
bign old = *this;
++(*this);
return old;
} bign bign::operator+=(const bign &num)
{
*this = *this + num;
return *this;
} bign bign::operator-(const bign &num) const
{
bign b=num,a=*this;
if (!num.sign && !sign)
{
b.sign=;
a.sign=;
return b-a;
}
if (!b.sign)
{
b.sign=;
return a+b;
}
if (!a.sign)
{
a.sign=;
b=bign()-(a+b);
return b;
}
if (a<b)
{
bign c=(b-a);
c.sign=false;
return c;
}
bign result;
result.len = ;
for (int i = , g = ; i < a.len; i++)
{
int x = a.s[i] - g;
if (i < b.len) x -= b.s[i];
if (x >= ) g = ;
else
{
g = ;
x += ;
}
result.s[result.len++] = x;
}
result.clean();
return result;
} bign bign::operator * (const bign &num)const
{
bign result;
result.len = len + num.len; for (int i = ; i < len; i++)
for (int j = ; j < num.len; j++)
result.s[i + j] += s[i] * num.s[j]; for (int i = ; i < result.len; i++)
{
result.s[i + ] += result.s[i] / ;
result.s[i] %= ;
}
result.clean();
result.sign = !(sign^num.sign);
return result;
} bign bign::operator*(const int num)const
{
bign x = num;
bign z = *this;
return x*z;
}
bign bign::operator*=(const bign&num)
{
*this = *this * num;
return *this;
} bign bign::operator /(const bign&num)const
{
bign ans;
ans.len = len - num.len + ;
if (ans.len < )
{
ans.len = ;
return ans;
} bign divisor = *this, divid = num;
divisor.sign = divid.sign = ;
int k = ans.len - ;
int j = len - ;
while (k >= )
{
while (divisor.s[j] == ) j--;
if (k > j) k = j;
char z[MAX_L];
memset(z, , sizeof(z));
for (int i = j; i >= k; i--)
z[j - i] = divisor.s[i] + '';
bign dividend = z;
if (dividend < divid) { k--; continue; }
int key = ;
while (divid*key <= dividend) key++;
key--;
ans.s[k] = key;
bign temp = divid*key;
for (int i = ; i < k; i++)
temp = temp * ;
divisor = divisor - temp;
k--;
}
ans.clean();
ans.sign = !(sign^num.sign);
return ans;
} bign bign::operator/=(const bign&num)
{
*this = *this / num;
return *this;
} bign bign::operator%(const bign& num)const
{
bign a = *this, b = num;
a.sign = b.sign = ;
bign result, temp = a / b*b;
result = a - temp;
result.sign = sign;
return result;
} bign bign::pow(const bign& num)const
{
bign result = ;
for (bign i = ; i < num; i++)
result = result*(*this);
return result;
} bign bign::factorial()const
{
bign result = ;
for (bign i = ; i <= *this; i++)
result *= i;
return result;
} void bign::clean()
{
if (len == ) len++;
while (len > && s[len - ] == '\0')
len--;
} bign bign::Sqrt()const
{
if(*this<)return -;
if(*this<=)return *this;
bign l=,r=*this,mid;
while(r-l>)
{
mid=(l+r)/;
if(mid*mid>*this)
r=mid;
else
l=mid;
}
return l;
} bign::~bign()
{
} int a[];
bign dp[][];
int n,k;
int main()
{
while(cin>>n>>k)
{ for(int i=; i<=n; i++)
{
cin>>a[i];
}
bign aa=,bb=;
for(int i=;i<=n;i++) {
for(int j=;j<=k;j++) dp[i][j]=aa;
}
for(int i=;i<=n;i++)dp[i][]=bb;
for(int i=;i<=n;i++) {
for(int j=;j<i;j++) {
if(a[i]>a[j]) {
for(int kk=;kk<=k;kk++) {
dp[i][kk]+=dp[j][kk-];
}
}
}
}
bign ans;
ans=dp[][k];
for(int i=;i<=n;i++)ans+=dp[i][k];
cout<<ans<<endl;
} return ;
}

代码

 

HDU5568/BestCoder Round #63 (div.2) B.sequence2 dp+高精度的更多相关文章

  1. HDU5569/BestCoder Round #63 (div.2) C.matrix DP

    matrix Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at fir ...

  2. BestCoder Round #63 (div.2)

    感觉有些无聊的比赛. A 暴力枚举下就行 B 简单的dp,但是wa了一发后就去先把C做了,然后发现如果输入的100个数,是如1,2,3,4,...,100,然后k=50,个数为c(100,50).果断 ...

  3. hdu5569 BestCoder Round #63 (div.2)

    题意: 给你一个矩阵,要求从左上角走到右下角,走个的费用:a[1]*a[2] + a[3]*a[4] + ......+ a[2n-1]*a[2n] 思路: 果然不机智,自己把自己套路了 对于每个奇数 ...

  4. HDU5567/BestCoder Round #63 (div.2) A sequence1 水

    sequence1  Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for a ...

  5. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  6. BestCoder Round #68 (div.2) tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  7. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  9. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. 从零开始学ios开发(四):IOS控件(1),Image View、Text Field、Keyboard

    长话短说,谢谢大家的关注,这篇写了好长时间,下面继续学习ios.我将用2到3篇的篇幅来学习iphone上的一些常用控件,包括Image View.Text Field.Keyboard.Slider等 ...

  2. [转]linux中强大的screen命令

    [转]linux中强大的screen命令 http://pythonorg.diandian.com/post/2012-01-05/40027464147 今天用SCREEN用点生了,有几个功能不知 ...

  3. GitFlow教程

    GitFlow教程 这份教程是博主学到的git基础,仅适合小团队使用,仅供参考 配置Git 配置github上面的账号,首先需要自己在git上注册一个账号 git config --global us ...

  4. 硬件描述语言Verilog设计经验总结

    一.硬件描述语言Verilog 粗略地看Verilog与C语言有许多相似之处.分号用于结束每个语句,注释符也是相同的(/* ... */和// 都是熟悉的),运算符"=="也用来测 ...

  5. STL学习三:deque容器

    1.Deque简介 deque是“double-ended queue”的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. deque在接口上和vector非常 ...

  6. Postgresql 存储过程调试 1

    看来人真的有些力不从心,半个月前还很得意掌握的简单的Postgresql 存储过程的调试,一段时间没使用,做新功能就忘了! Postgresql 在开源的数据库里面算是很强悍的了,但现在就是不方便调试 ...

  7. 分布式架构--第一篇--项目拆分(maven命令生成多模块项目)

    预览生成的项目结构: ying-yue-parent // 顶级总编译控制模块 ying-yue-lib // jar模块 ying-yue-model // 模型对象模块 ying-yue-dao ...

  8. js之变量和作用域

    JS的变量和其他语言的变量有很大区别.JS变量时“松散型”的,决定它只是在特定时间用于保存特定的一个名字而已.由于不存在变量要保存何种数据类型,变量的值和其数据类型可以在脚本的生命周期内改变. JS两 ...

  9. 简单修改 MySQL 的 root 账号密码

    首先这是一篇非常非常初级的教程. 平时为了方便,经常是直接在网上下载 PHP + MySQL 的集成环境,但有一些 MySQL 的 root 账号是没有密码的(例如大名鼎鼎的 XAMPP 就是这样), ...

  10. 团队开发——Alpha版总结会议

    本组目前存在的问题: 1.在选题的时候,题目选的比较有难度,造成后期工作量较大,实现有难度(未能正确估计项目的难度). 2.最初规划时,设计的功能较多,但是技术水平达不到,导致目前完成功能较少. 3. ...