【HDU】 1028 Ignatius and the Princess III
来源:互联网 发布:软件企业证书有效期 编辑:程序博客网 时间:2024/05/01 22:51
Ignatius and the Princess III
- 题目链接
- Ignatius and the Princess III
- 题目大意
给你一个数n,让你求他的所有分解式有多少个,i+j和j+i视为相同的等式。
- 题解
就是个分解问题,设f(i,j)为数i不大于j的分解方法数,这样我们要求的就是f(n,n)。很容易通过定义写出f的递推式:
f(i,j)=sum( f(i-k,k) ) 1<=k<=j ;
除了f(0,0)=1,i < j时其实就是i=j的情况。
注意推的时候用d[i][j]保留f[i][j]时的解,不知道会不会超时,记录下来肯定没有坏处….
- 代码
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int d[125][125],n;int f(int i,int j){ int sum=0; if (i<j) return f(i,i); if (d[i][j]) return d[i][j]; for (int k=j;k>=1;k--) sum+=f(i-k,k); return d[i][j]=sum;}int main(){ d[0][0]=1; while (scanf("%d",&n)!=EOF) { printf("%d\n",f(n,n)); } return 0;}
0 0
- hdu 1028 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- HDU-1028-Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- hdu 1028 Ignatius and the Princess III
- HDU--1028 Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III
- Ignatius and the Princess III hdu 1028
- c++快速简易入门教程_002构造函数
- H5修改url之pushState()和页面下拉加载判断
- nrf51822 --- 配对绑定输入密码(pair)
- 关于ListView的getItemViewType()这个方法的踩坑叙述
- c++快速简易入门教程_003析构函数
- 【HDU】 1028 Ignatius and the Princess III
- Leetcode_86_Partition List
- 使用SQL Server发布数据库快照遇到错误:对路径”xxxxx“访问被拒绝的解决方法
- Android中复制及粘贴功能
- 如何用js得到当前页面的url信息方法(JS获取当前网址信息)
- java单例模式使用及注意事项
- dumpsys
- c++快速简易入门教程_004函数的重载
- 为了明天加油