UVA11069 - A Graph Problem(DP)

题目链接

题目大意:给你n个点。要你找出有多少子串符合要求。首先没有连续的数字,其次不能再往里面加入不论什么的数字而不违反第一条要求。

解题思路:要发现每一个数字选定后。之后能够有两种选择。所以f(n) = f(n + 2) + f(n + 3);边界:当无法往下加入数字的时候那么返回1.

代码:

#include <cstdio>
#include <cstring> const int maxn = 100; int n;
int dp[maxn]; void init () { memset (dp, 0, sizeof (dp));
} int solve (int k) { if (k + 2 > n)
return dp[k] = 1;
if (dp[k])
return dp[k]; int &ans = dp[k];
if (k + 2 <= n)
ans += solve(k + 2);
if (k + 3 <= n)
ans += solve(k + 3);
return ans;
} int main () { while (scanf ("%d", &n) != EOF) { init();
int ans = solve(1);
if (n > 1)
ans += solve(2);
printf ("%d\n", ans);
}
return 0;
}

UVA11069 - A Graph Problem(DP)的更多相关文章

  1. D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )

    D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...

  2. codeforces 340D Bubble Sort Graph(dp,LIS)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud  Bubble Sort Graph Iahub recently has lea ...

  3. CF459E Pashmak and Graph (DP?

    Codeforces Round #261 (Div. 2) E - Pashmak and Graph E. Pashmak and Graph time limit per test 1 seco ...

  4. Codeforces 706 C. Hard problem (dp)

    题目链接:http://codeforces.com/problemset/problem/706/C 给你n个字符串,可以反转任意一个字符串,反转每个字符串都有其对应的花费ci. 经过操作后是否能满 ...

  5. Codeforces Gym 100342D Problem D. Dinner Problem Dp+高精度

    Problem D. Dinner ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1003 ...

  6. hdu 5464 Clarke and problem dp

    Clarke and problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...

  7. uva 10401 Injured Queen Problem(dp)

    题目链接:10401 - Injured Queen Problem 题目大意:给出一个字符串,要求在n * n(n为字符串的长度)的棋盘上摆放n个受伤的皇后,受伤的皇后只能攻击到同一列和它周围8个格 ...

  8. acdream 1222 Quantization Problem [dp]

    称号:acdream 1222 Quantization Problem 题意:给出一个序列 a ,然后给出一个 n * m 的矩阵,让你从这个矩阵中选出一个序列k,使得sum(abs(ki - ai ...

  9. Codeforces 1096D - Easy Problem - [DP]

    题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符 ...

随机推荐

  1. 字符串如何判断null.

    转http://blog.sina.com.cn/s/blog_48cd37140101awgq.html Java中判断String不为空的问题 一.判断一个字符串str不为空的方法有: 1. st ...

  2. 【细说Java】揭开Java的main方法神秘的面纱(转)

    大家都知道,main方法是Java应用程序的入口,其定义格式为: public static void main(String[] args) 可是为什么要这么定义呢?不这样定义可以么?main方法可 ...

  3. socket通信技术介绍

    [-] 网络中进程之间怎样通信 什么是Socket socket一词的起源 socket的基本操作 socket函数 bind函数 网络字节序与主机字节序 listenconnect函数 accept ...

  4. HDU1005(周期问题)

    Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * ...

  5. BZOJ 1014: [JSOI2008]火星人prefix( splay + hash )

    用splay维护序列, 二分+hash来判断LCQ.. #include<bits/stdc++.h> using namespace std; typedef unsigned long ...

  6. android4.0移植,拨号异常

    D/dalvikvm( 2274): GC_CONCURRENT freed 206K, 12% free 6571K/7431K, paused 2ms+3ms D/dalvikvm( 2274): ...

  7. VS2008 Project : error PRJ0019: 某个工具从以下位置返回了错误代码: "正在执行生成后事件..."解决方案

    右键工程属性 -> 配置属性 -> 生成事件 ->生成后事件,命令行中的路径加上双引号,如 copy $(ProjectDir)\export\win32\Debug\$(Proje ...

  8. PredictionIO Open Source Machine Learning Server

    PredictionIO Open Source Machine Learning Server Build Smarter Software with Machine Learning Predic ...

  9. iOS 使用Block实现函数回调

    事实上.iOS中的Block就是C++中的函数指针,实现方式都是一样的,以下贴出一个简单的实践. 首先,创建一个回调的类 BlockStudy.h // // BlockStudy.h // Bloc ...

  10. Android_Service组件详解

    1.Service概述 Service服务是一个没有用户界面的在后台运行执行操作的应用组件,其它组件可以通过Intent意图启动这个Service去完成特定的功能,比如通过Service可以完成播放音 ...