HDU 5965 枚举模拟 + dp(?)

ccpc合肥站的重现...一看就觉得是dp 然后强行搞出来一个转移方程 即 根据第i-1列的需求和i-1 i-2列的枚举摆放 可以得出i列摆放的种类..加了n多if语句...最后感觉怎么都能过了..然而不是t就是wa..最后看别人的题解 我的dp转移是9*O(n)的 常数要t..

别人的题解居然都是用模拟的..根据枚举第一列可以得出第二列的摆放姿势 由这两个摆放和第二列的需求可以求出来第三列..以此类推 最后check一下最后两个..

叉姐的题解里面写了一个dp转移方程..然而并不能看懂..放牛说用状压搞一发就行...有空再补吧..

枚举第一列的模拟版本

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define L long long
char s[10050];
L a[10050];
L b[10050];
L d(L a){
    if(a == 1){
        return 2;
    }
    else {
        return 1;
    }
}
const L mod = 100000007;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",s);
        int len = strlen(s);
        for(int i=1;i<=len;i++){
            a[i] = s[i - 1] - ‘0‘;
        }
        if(len == 1){
            if(a[1] == 1){
                printf("2\n");
            }
            else if(a[1]==0 || a[1] == 2){
                printf("1\n");
            }
            else {
                printf("0\n");
            }
            continue;
        }
        L ans = 0;
        for(L i=0;i<=2;i++){ /// 枚举第一列放多少
            b[1] = i;
            b[2] = a[1] - i;
            L sum = d(b[1])*d(b[2]); /// 初始状态的种数
            if(b[2] < 0 || b[2] > 2)continue;
            for(int j=3;j<=len;j++){
                b[j] = a[j - 1] - b[j - 1] - b[j - 2];
                if(b[j] < 0 || b[j] > 2){
                    sum = 0;
                    break;
                }
                sum *= d(b[j]);
                sum %= mod;
            }
            if(b[len] + b[len-1] != a[len]){
                sum = 0;
            }
            ans += sum;
            ans %= mod;
        }
        printf("%lld\n",ans);
    }
}

  

时间: 2024-08-25 22:22:29

HDU 5965 枚举模拟 + dp(?)的相关文章

HDU 5965(三行扫雷 dp)

题意是在一个 3 行 n 列的图上进行扫雷,中间一行没有雷,且中间一行的每一格都会显示周围的雷数,问根据已知的雷数在上下两行设置地雷的方法数. 分析知每一列所填雷数的和与周围的雷数有关,但每列具体的填法只影响方法数,不影响周围的雷数统计,而且每列的雷数只有 0,1,2 这三种, 用数组 dp[ ] 来记录每列的雷数,用数组 a[ ] 来记录所给的信息( 每一列出现的周围雷数的统计 ),则: dp[ pos ] = a[ pos - 1 ] - dp[ pos - 1 ] - dp[ pos -

HDU 4930 Fighting the Landlords(暴力枚举+模拟)

HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型,如果先手能一步走完,或者一步让后手无法管上,就赢 思路:先枚举出两个人所有可能的牌型的最大值,然后再去判断即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Player { int rank[15]; } p1, p2; int t, h

HDU 3709 Balanced Number 枚举+数位DP

枚举支点之后数位DP,注意姿势 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list&g

HDU 4960 (水dp)

Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi

hdu 4089 不错的DP 北京现场赛题

http://acm.hdu.edu.cn/showproblem.php?pid=4089 还有疑惑,需要重新推: 但是学到的: 1.A=a+b+c  abc是三种情况,那么P(A)=a*P(a->事件)+b*P(b->事件)+c*P(c->事件); a->事件意思是 在a情况下的事件,就是全概率公式的思想吧 2.一定注意每一步会不会出现分母为0 的情况,以及预处理的时候对于一些特殊情况导致自己的式子会出现分母为0的排除掉 3.概率DP经常出现推出了式子但是自己不会写代码的情况,

hdu 4945 2048 (dp+组合数)

2048 Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 840    Accepted Submission(s): 199 Problem Description Teacher Mai is addicted to game 2048. But finally he finds it's too hard to get 2048.

HDU 4945 2048(dp)

题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 . 比赛的时候想着1跟3可以合并成4 ....然后就越搞越复杂了.....2048玩得不多的我没有透彻的合并规则概念..... 看了题解写了发,妥妥地TLE...本地随意n=100,000都TLE了... 用dp[i][j]表示当前 i个2^j 的方案数 然后队友提醒优化,就是,当枚举到比如,value =

CUGBACM_Summer_Tranning3 2013长沙现场赛(二分+bfs模拟+DP+几何)

A题:二分 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 用lower_bound可以轻松解决,不过比赛的时候逗逼了. 刚开始没有预处理,所以队友给出一组数据的时候没通过,然后一时紧张又想不出什么好的解决办法,所以就没再继续敲代码.实在有点可惜了. #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #includ

HDU 1058 Humble Numbers (dp+打表)

先是想筛法素数表啊,然后1~2000000000枚举打表啊,结果越想越不对. 后来想到唯一分解定理,可是怎么实现呢..果然还是需要努力啊.. 研究了discuss代码,码之~ ~~~~ dp的思想,若dp[i]是Humble Numbers,那么dp[i]*2,dp[i]*3,dp[i]*5,dp[i]*7都将是Humble Numbers. 所以只需要注意连续性便好了. #include<cstdio> #include<algorithm> #include<cmath&