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