Ural 1081 Binary Lexicographic Sequence(DP)
来源:互联网 发布:淘宝技术删除中差评 编辑:程序博客网 时间:2024/05/17 05:56
题目地址:Ural 1081
先用dp求出每个长度下的合法序列(开头为1)的个数。然后求前缀和。会发现正好是一个斐波那契数列。然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int INF=0x3f3f3f3f;LL dp[3][50], sum[50], s[50];int main(){ int i, j, n, k; memset(dp,0,sizeof(dp)); dp[0][1]=0; dp[1][1]=1; sum[1]=2; s[1]=2; for(i=2; i<44; i++) { dp[1][i]+=dp[0][i-1]; dp[0][i]+=dp[0][i-1]+dp[1][i-1]; sum[i]=dp[0][i]+dp[1][i]; s[i]=s[i-1]+sum[i]; } /*for(i=1;i<=44;i++) { printf("%d ",s[i]); } puts("");*/ s[0]=1; while(scanf("%d%d",&n,&k)!=EOF) { if(k>s[n]) printf("-1\n"); else { while(n--) { if(k>s[n]) { printf("1"); k-=s[n]; } else printf("0"); } } } return 0;}
1 0
- Ural 1081 Binary Lexicographic Sequence(DP)
- ural 1081 Binary Lexicographic Sequence
- Ural 1081 Binary Lexicographic Sequence
- URAL 1081. Binary Lexicographic Sequence(简单dp)
- ural Binary Lexicographic Sequence (dp + dfs)
- URAL 1081 Binary Lexicographic Sequence (递推 + 递归)
- Ural 1081. Binary Lexicographic Sequence
- ural 1081. Binary Lexicographic Sequence
- Ural 1081. Binary Lexicographic Sequence
- 1081. Binary Lexicographic Sequence(dp)
- timus 1081. Binary Lexicographic Sequence URAL 解题报告
- Binary Lexicographic Sequence
- Timus 1081. Binary Lexicographic Sequence
- Binary Lexicographic Sequence_简单DP
- ural Brackets Sequence (dp)
- URAL 1183.Brackets Sequence ( DP+记录路径)
- 【URAL 1183】Brackets Sequence(区间DP+路径记录)
- Ural 1018 Binary Apple Tree (树形DP)
- Spring中常用的hql查询方法 (getHibernateTemplate())(
- CCNA学习笔记Day2
- C++虚表、虚指针
- 资源限制阈值
- 农业银行K宝不能下载证书
- Ural 1081 Binary Lexicographic Sequence(DP)
- 梯度下降(Gradient Descent),一句代码,一个式子
- 第9周 项目2-3 运用for语句做循环程序求正负分数累加和
- spring定时器
- Cookie与Session机制,什么时候用Cookie,什么时候用Session
- Unity3D KeyCode
- CSS3如何实现超出指定文本以省略号显示效果
- 在 Unity 工程 (Project) 中使用 DLL(动态库)
- 金色十月线上编程比赛第二题:解密