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

题意:给出n个数,求长度为m的递增子序列的数目。

思路:状态转移方程 dp[i][j] = sum(dp[k][j-1]| k < i &&a[k]<a[i])  表示前i个元素中长度为j的递增子序列的数目

 #include <stdio.h>
#include <string.h>
const int N=;
__int64 dp[N][N];
__int64 a[N];
int main()
{
__int64 n,m;
while(~scanf("%I64d%I64d",&n,&m))
{
if (n==&&m==)
break;
memset(dp,,sizeof(dp));
for (int i = ;i <= n; i++)
{
scanf("%I64d",&a[i]);
dp[i][] = ;
}
for (int i = ;i <= n; i++)
{
for (int j = ;j <= m; j++)
{
for (int k = ;k < i; k++)
{
if (a[k] < a[i]) //前i个数长度为j的递增子序列数目
//=(a[i] > a[k]&&k < i)前k个数中长度为j-1的递增子序列数目的和
dp[i][j]+=dp[k][j-];
}
}
}
__int64 ans = ;
for (int i = ;i <= n; i++)
ans+=dp[i][m];
printf("%I64d\n",ans);
}
return ;
}

最新文章

  1. C#网络编程——IPHostEntry
  2. OutofMemory之PermGen介绍
  3. 学习笔记——k近邻法
  4. 如何使用 HTML5 Canvas 制作水波纹效果
  5. Exception:A generic error occurred in GDI+
  6. HDU1003 Max Sum(求最大字段和)
  7. php 加密解密方法
  8. Android之fragment点击切换和滑动切换结合
  9. asp.net微信开发第一篇----开发者接入
  10. Java笔记--Java的List、Iterator用法
  11. nginx使用ssl模块配置支持HTTPS访问【解决ssl错误】
  12. 使用scp从远程服务器下载文件到本地
  13. java中文拼音字母排序
  14. Docker进阶之九:Dockerfile 及 通过Dockerfile搭建lnmp
  15. MVC5 Razor视图中不规范书写导致的编译问题
  16. 安装Linux内核源代码
  17. 初学python---排序
  18. 关于 win10启动错误 Error:16
  19. Linux 中的 Install命令
  20. canvas图像保存

热门文章

  1. moongoTemplate使用
  2. 最大子段和(洛谷P1115,动态规划递推)
  3. PHP代码静态分析工具PHPStan
  4. vue父组件向子组件传递参数
  5. 7-26 Windows消息队列
  6. 百练2815:城堡问题(DFS)
  7. Windows 硬件开发人员怎样选择代码签名证书类型
  8. Bugzilla 系统企业应用案例
  9. Hihocoder 1337 (splay)
  10. 非常适合新手的jq/zepto源码分析08---ajax的封装