BUPTOJ 1504
来源:互联网 发布:管家婆软件怎样做库存 编辑:程序博客网 时间:2024/06/07 14:56
北邮校赛的H题。
一开始乱搞,WA了,后来DP了一下,分四种情况就可以。
#include <iostream>#define inf 1<<28using namespace std;int a[3000];int main(){ int T; for (int i = 0 ;i <= 2222; i ++)a[i] = inf ; a[1] = 1;a[2] = 2 ;a[3] = 3;a[4] = 4;a[5] = 5;a[6] = 5;a[7] = 6;a[8] = 6;a[9] = 6;//手算的初值 for (int i = 9 ;i <= 2005 ;i ++) { for (int j = i - 1 ;j >= 1; j --) { int t1 = i/j;//复制的次数 int t2 = i%j;//加的次数 a[i] = min(a[i],t1 - 1 + t2 + 1 + a[j]);//复制 a[i] = min(a[i], a[j] + i - j);//加 a[i - 1 ] = min(a[i - 1], a[i] + 1);//删除 } for (int j = i + 1 ;j <= 2005 ;j ++) a[j] = min(a[j] , a[j- 1 ] + 1);//后一位加一 } int d; while(cin >> d) cout <<a[d]<<endl; return 0;}
- BUPTOJ 1504
- BUPTOJ 1501
- buptoj:network
- BUPTOJ 0087-0089
- BUPTOJ 0090 字符串转换
- BUPTOJ 0091 文件系统
- BUPTOJ 407. BLOCKS
- BUPTOJ 0092统计节点个数
- BUPTOJ 409. 数的关系
- buptoj 945:Emiya 树形dp
- buptoj:Study sister's dragon
- buptoj 941:Mr.L's Journey
- buptoj 942:Lettree's Math Homework
- poj 1504
- POJ 1504
- poj 1504
- poj 1504
- poj 1504
- “百度之星”程序设计大赛试题解答(Java实现)
- 关于namenode安全模式
- 基于ARM的RAM存储器接口设计
- Javascript两种方法实现数秒自动关闭弹窗
- SQLServer 将两行数据合并到一行
- BUPTOJ 1504
- linux 下使用truecrypt
- Redis学习(1)——下载与配置
- 关于tq2440开发板的led驱动
- 虚函数的作用
- std::nth_element 排序
- 使用Aspose.Pdf置文档窗口和页面显示属性
- Flask+SAE快速打造微信公众帐号(有码)
- 长整形转换为字符串