fzoj 1320 Ones(动态规划:水题)
来源:互联网 发布:日本女演员知乎 编辑:程序博客网 时间:2024/06/05 11:27
Problem 1320 Ones
Accept: 567 Submit: 1996
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Given a positive integer N (0<=N<=10000), you are to find an expression equals to N using only 1,+,*,(,). 1 should not appear continuously, i.e. 11+1 is not allowed.
Input
There are multiple test cases. Each case contains only one line containing a integer N
Output
For each case, output the minimal number of 1s you need to get N.
Sample Input
210
Sample Output
27
Source
chenyan输出最少需要一个1
很水的一道题,重新开始刷我的DP
状态转移方程为:dp[i] = min(dp[j]+dp[i/j]+dp[i%j])
代码如下:
#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 10010using namespace std;int dp[MAXN];void init(int n) { for(int i=1; i<=n; ++i) { dp[i] = i; } dp[0] = 0; for(int i=1; i<=n; ++i) { for(int j=1; j<=i; ++j) { dp[i] = min(dp[i%j]+dp[j]+dp[i/j], dp[i]); } }}int main(void) { init(10010); int n; while(scanf("%d", &n) != EOF) { printf("%d\n", dp[n]); } return 0;}
0 0
- fzoj 1320 Ones(动态规划:水题)
- 动态规划(线性类)--ones 唯“一”运算
- LeetCode 474. Ones and Zeroes 动态规划解法+拓展
- leetcode 474. Ones and Zeroes 动态规划DP + 背包问题
- 算法题——Ones and Zeroes(JAVA)动态规划
- 动态规划——474. Ones and Zeroes[medium]
- FZOJ--2221-- RunningMan(水题)
- leetcode 600. Non-negative Integers without Consecutive Ones 非负整数不包括连续的1 + DP动态规划
- poj1163 动态规划 水题
- FZOJ--2212--Super Mobile Charger(水题)
- 动态规划!!!动态规划!!!
- foj 1320 Ones
- FOJ 1320 ones
- FOJ 1320 Ones
- Ones
- Ones
- Ones
- ones
- 【UI特效】FrameLayout实现ListView顶部悬停效果
- 狐言:王阳明心学、量子物理、心外无物的乱弹
- Java程序验证日期格式
- IOS 本地推送消息以及进入后台继续推送
- poj 2538 WERTYU
- fzoj 1320 Ones(动态规划:水题)
- 黑马程序员-----JAVA面向对象(二)
- cocos v3.2在vs2012下编译安装
- mysql 主从复制实现原理
- document.body和document.documentElement的区别
- Android中正则表达式使用
- hadoop远程调试
- NOT IN和NOT EIXTS的风险
- java 求日期差