HDU 5568 sequence2 区间dp+大数
题目链接:
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+大数的更多相关文章
- Hdu 5568 sequence2 高精度 dp
sequence2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=556 ...
- hdu 5396 Expression(区间dp)
Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...
- 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 ...
- Dire Wolf HDU - 5115(区间dp)
Dire Wolf Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total ...
- hdu 4579 博弈+区间dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...
- Hdu 2513 区间DP
Cake slicing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 ...
- HDU 4293---Groups(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...
- hdu 4597 + uva 10891(一类区间dp)
题目链接:http://vjudge.net/problem/viewProblem.action?id=19461 思路:一类经典的博弈类区间dp,我们令dp[l][r]表示玩家A从区间[l, r] ...
随机推荐
- js一些稀奇古怪的写法-带你装逼带你飞
//定时器的第三个参数 setInterval(function(str1,str2,num){ alert(str1+str2+num) },1000,'参数1','还可以有很多参数,不同的类型.. ...
- Like ruby of SBM Crusher zip to dict
how to use the zip to bulid a dict in python? data = """A dynamic, interpreted, open ...
- 利用RecyclerView CardView实现新闻卡片样式
引入的包: demo结构: 测试代码: News.java: package com.zzw.testcardview; import java.io.Serializable; public cla ...
- 【转】javascript性能优化-repaint和reflow
repaint(重绘) ,repaint发生更改时,元素的外观被改变,且在没有改变布局的情况下发生,如改变outline,visibility,background color,不会影响到dom结构渲 ...
- 金山词霸每日一句开放平台 .NET demo
先附上地址:http://open.iciba.com/?c=api 小金山提供了2种获取数据的方式 1. 通过填入自己的网站名称.网址.邮箱地址 来生成一段javascript脚本,直接将生成的代码 ...
- Flask Web Development —— Web表单(上)
Flask-WTF扩展使得处理web表单能获得更愉快的体验.该扩展是一个封装了与框架无关的WTForms包的Flask集成. Flask-WTF和它的依赖集可以通过pip来安装: (venv) $ p ...
- oracle11g 重新配置em
OS: ORACLE-LINUX 5.7 DB: 11.2.0.3 [oracle@b28-122 ~]$ emctl status dbconsoleOracle Enterprise Manage ...
- oracle 分析函数(笔记)
分析函数是oracle数据库在9i版本中引入并在以后版本中不断增强的新函数种类.分析函数提供好了跨行.多层次聚合引用值的能力.分析函数所展现的效果使用传统的SQL语句也能实现,但是实现方式比较复杂,效 ...
- 手动书写小代码-foreach实现机制
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- 在VS2010 SP1基础上安装mvc3
安装VS2010 SP1后,再安装mvc3会报错,估计原因是此安装包会安装VS的补丁,而sp1的补丁版本高过此安装包的. AspNetMVC3ToolsUpdateSetup.exe 解决办法: 运行 ...