非常感谢 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. Mysql开启远程

    改表法: x:\>mysql -u root -pvmware mysql> use mysql;mysql> update User set Host = ‘%’ where Us ...

  2. Python学习之字符串函数

    下面是在看python核心编程中序列字符串中提到的一些函数,根据自己的学习理解总结了下,方便日后用到的时候查看.    1.string.capitalize() 把字符串的第一个字符大写 例子:   ...

  3. python自学笔记(四)python基本数据类型之元组、集合、字典

    一.元组tuple 特性 1.有序集合 2.通过偏移来取数据 3.不可变对象,不能在原地修改内存,没有排序.修改等操作 元组不可变的好处:保证数据的安全,比如我们传给一个不熟悉的方法,确保不会改变我们 ...

  4. Springmvc异步上传文件

    <script src="js/jquery.js" type="text/javascript"></script><scrip ...

  5. 静态方法中为什么不能使用this

  6. python异常处理try,except,else,finally,raise

    先看下else的使用: try: ... exception: ... else: ... 只有在try中没有发生任何异常,所有代码完全成功的情况下才会转入else 再看下finally: final ...

  7. [C++ Basic] Const 用法

    定义: const 主要用于声明常量.当常量为对象时,对象值不可改变:当常量为指针时,该指针不可移动或重新赋值,但我们可以通过它去修改该指针的指向对象的值(前提是无需移动指针的修改).所谓的形参.返回 ...

  8. linux使用技巧(shell/vi/screen)

    1,Shell bash > awk '{print {NF}}' file 此时想修改操作命令可参照下面快捷方式 ctrl a 光标移动到命令最前面 ctrl e 光标移动到命令最后面 ctr ...

  9. Unity 对象池 生产 保存

    Unity对象池主要是保存那些常用的物体,避免他们在不断销毁和创造中损坏性能. 主要思路为:创造物体时,判断是否存在,如果存在则调用并使其显示.如果不存在则创造一个新的. 当销毁时,调用协程延时隐藏物 ...

  10. HDU 1045(质因数分解)

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Tomor ...