CSUOJ 1299 - Number Transformation II 打表预处理水DP
来源:互联网 发布:windows最新版本 编辑:程序博客网 时间:2024/05/29 18:36
http://122.207.68.93/OnlineJudge/problem.php?id=1299
第二个样例解释..
3 6
3->4->6..两步..
由此可以BFS也可以DP..但关键是要离线把100000内每个数的约数情况预先处理出来..否则会超时...
Program:
#include<iostream>#include<stdio.h>#include<cmath>#include<cstring>#include<string.h>#include<algorithm>#include<queue>#include<stack>#include<set>#define pi acos(-1)#define ll long long #define oo 2139062143#define MAXN 200005using namespace std;struct node{ int next;}h[MAXN];int n,m,dp[MAXN],p[3000000][2];int main(){ int x,i,k; m=0; memset(h,0,sizeof(h)); memset(p,0,sizeof(p)); for (i=1;i<=MAXN;i++) for (x=i*2;x<=MAXN;x+=i) { p[++m][0]=i; p[m][1]=h[x].next; h[x].next=m; } while (~scanf("%d%d",&n,&m)) { memset(dp,0x7f,sizeof(dp)); dp[n]=0; for (x=n;x<=m;x++) { k=h[x].next; while (k) { i=p[k][0]; if (x+i<=m) if (dp[x+i]==-1 || dp[x+i]>dp[x]+1) dp[x+i]=dp[x]+1; k=p[k][1]; } } if (dp[m]==oo) printf("sorry, can not transform\n"); else printf("%d\n",dp[m]); } return 0;}
- CSUOJ 1299 - Number Transformation II 打表预处理水DP
- HDU 4952 Number Transformation 打表规律
- codeforces Number Transformation II
- Number Transformation II CodeForces
- CodeForces346 C. Number Transformation II
- HDU 4151The Special Number(预处理打表+二分)
- HDOJ 1391 Number Steps(打表DP)
- Codeforces 346C Number Transformation II 构造
- Codeforces 347E - Number Transformation II
- codeforces 347 E Number Transformation II
- CSU 1090: Number Transformation 一个非常好的优先队列打表
- 【cdoj 1323】柱爷的下凡 dp打表预处理
- HDU 1502 Regular Words(打表预处理dp)
- Number Transformation
- Number Transformation
- Number Transformation
- hdu 5179 beautiful number(打表,数位DP)
- HDU 1058 Humble Number(打表dp)
- MyMinimad ── Linux下用libmad写的mp3解码播放程序
- jQuery插件开发
- 通告机制Notification
- PHPECLISPE+xampp环境配置
- KL25的AD采集操作
- CSUOJ 1299 - Number Transformation II 打表预处理水DP
- Entity Framework 全面教程详解
- 【TextView】Android TextView相关操作
- Linux:用at和crontab调度作业
- Multiplication Puzzle--动态规划
- 数据库复习4
- 我的外骨骼,诺基
- <我的外骨骼,诺基>后的访谈
- Ubuntu12.04下安装PHP5