1260. Nudnik Photographer
来源:互联网 发布:logo软件下载 编辑:程序博客网 时间:2024/05/16 04:44
我在做这道题的时候首先用的是回溯法,但是交上地 时候显示超时,下面我把用回溯法的代码贴出来。
#include <stdio.h>#include <math.h>int n,flag=0;int b[100],a[100];int main(){ void f(int x); int i,j,m,t; scanf("%d",&n)!=EOF flag=0; for(i=1;i<=n;i++) { a[i]=1; } b[1]=1; if(n>=2) { f(2); }else { flag=1; } printf("%d ",flag); return 0;}void f(int x){ int i,j; for(i=2;i<=n;i++) { if(a[i]==1&&abs(b[x-1]-i)<=2) { b[x]=i; a[i]=0; if(x<n) { f(x+1); }else { flag+=1; } a[i]=1; } }}
代码:
#include <stdio.h>int main(){ int i,j,n,m,s,t; int a[100]; a[1]=1;a[2]=1;a[3]=2; scanf("%d",&n); for(i=4;i<=n;i++) { a[i]=a[i-1]+a[i-3]+1; } printf("%d\n",a[n]); return 0;}
- 1260. Nudnik Photographer
- 1260. Nudnik Photographer dp
- Ural 1260. Nudnik Photographer
- URAL 1260. Nudnik Photographer
- ural 1260. Nudnik Photographer
- Ural 1260. A nudnik photographer
- Ural 1260. Nudnik Photographer DP
- ural 1260. Nudnik Photographer(dp)
- Nudnik Photographer
- Ural 1260. A nudnik photographer(dp)
- ural 1260. Nudnik Photographer 规律dp
- Ural 1260 Nudnik Photographer
- timus 1260. Nudnik Photographer 解题报告 URAL 找规律?DP
- Nudnik Photographer -Ural1260动态规划
- Ural 1260 A nudnik photographer(DP)
- URAL 1260 Nudnik Photographer 简单的递推
- C. Photographer
- Photographer (SDUT 2063)
- 创业必经之路——Paul Graham创业曲线
- C,C++,C#三者区别
- cmd 变量篇
- system server ANR 一种分析方法 -- Android JVM异常重启简析
- 《JavaScript DOM编程艺术》学习回顾2
- 1260. Nudnik Photographer
- MMSEG系统:中文分词入门之最大匹配法扩展
- Spring的template与callback模式
- UNRESOLVABLE GAP
- o4-tom's mystat.sql & mystat2.sql
- 河内之塔(Towers of Hanoi)
- 关于端口
- o5-tom大师构建大表脚本
- 控制版面里的添加删除程序打不开,提示rundll32.exe应用程序错误