hdu 1028 Ignatius and the Princess III
来源:互联网 发布:linux解压缩文件夹命令 编辑:程序博客网 时间:2024/05/29 09:30
hdu 1028 Ignatius and the Princess III 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028
题目大意:整数拆分。
题目分析:像用筛子筛数一样,从大到小筛。以4为例,先安排a[0]=1来兜底,拿出最大的数4,一个4就可以组成4,所以a[4]+=a[0];再3,一个3可以组成3所以a[3]+=a[0],一个3跟一个1可以组成4,所以a[4]+=a[1]可是此时a[1]还是0(没有组出数值1的方法),所以a[4]没变;2,a[2]变成了1,a[3]没变(因为此时a[1]还是0),a[4]变成了2(答案中添加了一种“2+2”);最后1来填满所有的缝,a[1]0→1,a[2]1→2,a[3]1→3,a[4]2→5。以上就是走完第一样例的全部流程了。
code:
#include<stdio.h>#include<string.h>int max(int a,int b){return a>b?a:b;}int main(){int a[130],i,j,n;while(scanf("%d",&n)!=EOF){memset(a,0,sizeof(a));a[0]=1;for(i=n;i>0;i--){for(j=i;j<=n;j++){a[j]+=a[j-i];}}printf("%d\n",a[n]);}return 0;}
PS:所有课本和资料上都说这是母函数的题,不过母函数的代码比我的还要麻烦一点。(我学母函数这些天做母函数的题几乎没用过母函数,是不是真不用学啊??)
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
- 关于map容器
- Android NDK学习(6)在Android项目中调用已有.so库
- activemq和jms是种什么关系
- 【R语言系列】R的列表
- 一种排序 sort cmp STL
- hdu 1028 Ignatius and the Princess III
- 存储基础
- 指针函数与函数指针的区别
- 判断一点是否在矩形中,已知矩形的顶点坐标
- 死光光的时光的时光说过
- eclipse安装完ADT插件后,在导航栏找不到插件图标
- 利用大数据帮助农户优化农场配置,旧金山创业公司Ceres Imaging想打造“数据即服务”的2C服务公司
- Android 个性化控件(View)篇
- Message Flood