题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5568

题意:

求所有长度为k的严格升序子序列的个数。

题解:

令dp[i][k]表示以i结尾的长度为k的所有严格升序子序列的个数,则有状态转移:dp[i][k]+=dp[j][k-1](其中,arr[i]>arr[j],并且i>j);

最后答案为dp[1][k]+...dp[n][k]。

代码:

 import java.util.*;
import java.math.*;
public class Main { public static void main(String args[]){
Scanner cin = new Scanner(System.in);
final int maxn=;
int n,k;
int[] arr=new int[maxn]; while(cin.hasNext()){
n=cin.nextInt();
k=cin.nextInt();
BigInteger[][] dp=new BigInteger[maxn][maxn];
for(int i=;i<=n;i++){
arr[i]=cin.nextInt();
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++) dp[i][j]=BigInteger.ZERO;
}
for(int i=;i<=n;i++) dp[i][]=BigInteger.ONE;
for(int kk=;kk<=k;kk++){
for(int i=;i<=n;i++){
for(int j=i-;j>=;j--){
if(arr[i]>arr[j]){
dp[i][kk]=dp[i][kk].add(dp[j][kk-]);
}
}
}
}
BigInteger ans = BigInteger.ZERO;
for(int i=;i<=n;i++) ans=ans.add(dp[i][k]);
System.out.println(ans.toString());
}
}
}

HDU 5568 sequence2 区间dp+大数的更多相关文章

  1. Hdu 5568 sequence2 高精度 dp

    sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...

  2. hdu 5396 Expression(区间dp)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...

  3. You Are the One HDU - 4283 (区间DP)

    Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...

  4. Dire Wolf HDU - 5115(区间dp)

    Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total ...

  5. hdu 4579 博弈+区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...

  6. Hdu 2513 区间DP

    Cake slicing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. HDU 4283---You Are the One(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as Y ...

  8. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

  9. hdu 4597 + uva 10891(一类区间dp)

    题目链接:http://vjudge.net/problem/viewProblem.action?id=19461 思路:一类经典的博弈类区间dp,我们令dp[l][r]表示玩家A从区间[l, r] ...

随机推荐

  1. LINUX下网站压力测试工具webbench

    wget http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz tar zxvf webbench-1.5.tar.gz cd we ...

  2. 例题6-10 The Falling Leaves,UVA699

    这道题我的思路是先通过递归构建树,然后进行遍历将位置和保存在map映射中,最后按顺序输出map集合中的值. 至于如何遍历,我是依次尝试了宽度优先遍历和深度优先遍历,当然这都是可以的.不过期间写错了很多 ...

  3. 使用DBCP时发生AbstractMethodError异常

    使用DBCP时发生AbstractMethodError异常,错误描述: Exception in thread "main" java.lang.AbstractMethodEr ...

  4. 重拾C,一天一点点_10

    来博客园今天刚好两年了,两年前开始学编程. 忙碌近两个月,项目昨天上线了,真心不容易,也不敢懈怠,接下来的问题会更多.这两天调试服务器,遇到不少麻烦. 刚出去溜达了一下,晚上天凉了,现在手感觉凉的有点 ...

  5. UltraEdit中使用正则表达式

    正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串一定在行尾 ? 匹配除换行符外的任一单个字符. * 匹配任意个 ...

  6. 关键字替换排除HTML标签属性字符

    解决办法: 1.打开文件e/class/functions.php 2.找到函数 ReplaceKey($newstext,$classid=0) 3.找到替换代码 if(STR_IREPLACE) ...

  7. 2016/09/21 java split用法

    public String[] split(String regex) 默认limit为0 public String[] split(String regex, int limit) 当limit& ...

  8. MVC的Filters(拦截过滤)的Error页面,支持Ajax报错

    报错拦截过滤到error页面 [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, A ...

  9. ruby 笔记

    symbol 不能有- 'data-turbolinks-track' => true stop rails –s kill -INT $(cat tmp/pids/server.pid) cl ...

  10. "大账户"时代

    当要下载某文件时,哪怕是免积分,也需要登陆账户才能下载.  当要浏览某论坛时,只有注册账户,才可以浏览帖子.  当要网购商品时,必须注册账户,还要有众多宝宝平台,才可以实现交易.  当要团购时,必须先 ...