非常感谢 Potaty 大大的援助使得我最后A出了这两题DP

==================================

189A : 求切分后的ribbon最多的数目,不过要求切分后只能存在a or b or c 的长度

O(n)的效率:遍历下来求 f[i - a]、f[i - b]、 f[i - c] 中的最大值

如果i - a || b || c 的值小于0那么跳过

来一张图,过程非常清晰

当然,初始化对f 数组置-INF,否则可能出错

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ; int f[]; int main(){
int i, j, k, t, n, m, numCase = ;
int a, b, c;
while(cin >> n >> a >> b >> c){
for(i = ; i <= n; ++i){
f[i] = -INF;
}
f[] = ;
for(i = ; i <= n; ++i){
int tempa = i - a;
int tempb = i - b;
int tempc = i - c;
if(tempa >= ){
checkmax(f[i], + f[tempa]);
}
if(tempb >= ){
checkmax(f[i], + f[tempb]);
}
if(tempc >= ){
checkmax(f[i], + f[tempc]);
}
}
cout << f[n] << endl;
} return ;
}

======================================

166E: 这也是一道DP

起点在D,然后这是一个四面体

不难发现,其实A,B,C 是一样的,所以就不需要多开空间浪费了

需要开两个数组a[2] , b[2] 就够了

(通过 i & 1 来判断奇偶,还是头一次用TVT~)

这道题目通过过程模拟可以一下子发现规律:

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ; int main(){
int i, j, k, t, n, m, numCase = ;
ll a[], b[];
while(EOF != scanf("%d",&n)){
memset(a, , sizeof(a));
memset(b, , sizeof(b));
a[] = ;
for(i = ; i <= n; ++i){
a[i & ] = ( * b[!(i & )]) % MOD;
b[i & ] = (( * b[!(i & )]) + a[!(i & )]) % MOD;
}
cout << a[n & ] << endl;
} return ;
}

CodeForces 189A 166E 【DP ·水】的更多相关文章

  1. Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题

    除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...

  2. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  3. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  4. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  5. CodeForces 706C Hard problem (水DP)

    题意:对于给定的n个字符串,可以花费a[i]  将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][max ...

  6. Codeforces 474D Flowers dp(水

    题目链接:点击打开链接 思路: 给定T k表示T组測试数据 每组case [l,r] 有2种物品a b.b物品必须k个连续出现 问摆成一排后物品长度在[l,r]之间的方法数 思路: dp[i] = d ...

  7. codeforces 637D D. Running with Obstacles(dp,水题,贪心)

    题目链接: D. Running with Obstacles time limit per test 2 seconds memory limit per test 256 megabytes in ...

  8. Codeforces 189A:Cut Ribbon(完全背包,DP)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  9. dp水题 序列问题 (9道)

    9道题.A了8道,A题看题解也没弄懂怎么维护m段子序列的,过一段时间再回来看看     dp试水 47:56:23 125:00:00   Overview Problem Status Rank ( ...

随机推荐

  1. codeforces 613A. Peter and Snow Blower

    题目链接 给一个多边形, 一个多边形外的定点, 求这个点距离多边形的最短距离和最长距离. 最长距离肯定是和某个顶点的连线, 而最短距离是和点的连线或是和某条边的连线. 对于一条边上的两个点a, b, ...

  2. IOS 特定于设备的开发:UIDevice

    UIDevice类展示了一些关键的特定于设备的属性,包括使用的iPhone ,Ipad或iPod Touch型号.设备名称.以及OS名称和版本. 他是一种一站式解决方案,用于提取出某些系统详细信息.每 ...

  3. Win32 GDI基础(笔记)

    1.GDI名字的意义 GDI Graphic Device Interface,我说不清和GUI有什么区别.可能一种针对设备,一种针对用户而言吧,反正以后都说GDI,也就是Windows的图形编程. ...

  4. PLSQL 导入表到Oracle------》从一个表空间导入到其它表空间

        在用PLSQL导入.dmp文件到Oracle时出现的问题如下: Import started on 2015/11/18 10:42:44E:\oracle\product\10.2.0\db ...

  5. 禁止apache显示目录索引

    1)修改目录配置: 复制代码 代码如下: <Directory "D:/Apache/blog.phpha.com">Options Indexes FollowSym ...

  6. lightoj Again Array Queries

    1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...

  7. MongoDB初探系列之二:认识MongoDB提供的一些经常使用工具

    在初探一中,我们已经能够顺利的将MongoDB在我们自己的机器上跑起来了. 可是在其bin文件夹以下另一些我们不熟知的工具.接下来,将介绍一下各个小工具的用途以及初探一中MongoDB在data文件夹 ...

  8. 面试之hack(转载)

    史上最全的CSS hack方式一览 css hack api   做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我们会极不情愿的使用这个不太友好的方 ...

  9. 【Linux命令】配置ssh远程连接步骤

    安装ssh: sudo apt-get update sudo apt-get install openssh-server 查看ssh服务器是否启动: sudo ps -e | grep ssh 查 ...

  10. Sticks(poj 1011)

    题目描述: Description George took sticks of the same length and cut them randomly until all parts became ...