首页 > 其他 > 详细

洛谷 P3015 [USACO11FEB]最好的括号Best Parenthesis

时间:2017-11-05 19:47:15      阅读:301      评论:0      收藏:0      [点我收藏+]

传送门

题目大意:给出括号的得分标准。

()得分为1,如果A的得分为S(A),那么

(A)的得分为2*S(A)。

题解:搜索

 

技术分享
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 100009
#define LL long long
#define mod 12345678910LL
using namespace std;

int n,top;

int sta[N],pos[N];

LL dfs(int l,int r){
    LL ret=0;
    int rr=pos[l];
    if(rr-l==1)ret=(ret%mod+1%mod)%mod;
    if(l!=rr-1)ret=(ret%mod+2*dfs(l+1,rr-1)%mod)%mod;
    if(rr+1<=r)ret=(ret%mod+dfs(rr+1,r)%mod)%mod;
    return ret%mod;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        if(x==0)
         sta[++top]=i;
        else 
         if(top)
          pos[sta[top--]]=i;
    }
    cout<<dfs(1,n);
    return 0;
}
View Code

 

洛谷 P3015 [USACO11FEB]最好的括号Best Parenthesis

原文:http://www.cnblogs.com/zzyh/p/7788260.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!