NYOJ 708 ones
来源:互联网 发布:怎么打开php文件 编辑:程序博客网 时间:2024/04/29 05:38
http://acm.nyist.net/JudgeOnline/problem.php?pid=708
动态规划的题目,还是老方法,关键在于动态转移方程。
#include<iostream>#include<cmath>#include<cstdio>#include<cstring>using namespace std;int dp[10010];int minn(int a,int b){ a = a<b?a:b; return a;}void DP(){ dp[1] = 1; dp[2] = 2; int i,j; for(i = 3; i <= 10010; i++) { dp[i] = i; for(j = 1; j <i; j++) { dp[i] = minn(dp[i],dp[i-j] + dp[j]); if(j != 1 && i % j == 0) dp[i] = minn(dp[i],dp[i/j] + dp[j]); } }}int main(){ //freopen("2.txt","w",stdout); int n; memset(dp,0,sizeof(dp)); DP(); while(cin>>n) { cout<<dp[n]<<endl; } return 0;}
0 0
- nyoj 708 ones
- NYOJ 708 ones
- NYOJ 708 ones
- Nyoj 708 Ones
- NYOJ 708 ones
- ones(nyoj 708)
- nyoj-708 ones【线性dp】
- NYOJ ones
- nyoj ones
- NYOJ 题目708 ones(dp水)
- NYOJ - ones(dp)
- nyoj ones (DP)
- nyoj 410 how many ones?
- nyoj 410 how many ones?
- NYIST 708 ones
- NYIST 708 ones java
- Ones
- Ones
- mysql 优化
- android查询数据库获得手机里面所有的联系人
- 关于连连看随机排列的算法
- ReportStudio入门教程(十一) - 列表的复杂表头之页眉
- JavaScript学习记录——JsDoc学习
- NYOJ 708 ones
- stm32 -- RTC
- emacs中怎样修改Major Mode的快捷键
- PL/SQL 面向对象oop编程
- 删除Oracle中的重复记录
- Add cells, rows, or columns to an Excel document
- android 组件长按弹出上下文菜单
- codeforces#191_div2_C Magic Five 矩阵快速幂
- OpenCV IplImage数据结构