【TopCoder SRM714】ParenthesisRemoval

相关链接

题目传送门:https://community.topcoder.com/stat?c=problem_statement&pm=14595&rd=16883

解题报告

不难发现,这就是统计括号匹配的方案数
不会的同学可以先去切BZOJ 3622

Code

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 3000;
const int MOD = 1000000007;

int n,ans;
char s[N]; 

class ParenthesisRemoval {
    public:
    	int countWays(string ss) {
			n = ss.size();
    		for (int i=0;i<ss.size();i++) {
				s[i] = ss[i];
			}
			ans = 1;
			for (int i=0,pfx=0;i<n;i++) {
				if (s[i] == '(') {
					++pfx;
				} else {
					ans = (LL)ans * (pfx--) % MOD;
				}
			}
    	    return ans;
   		}
   	private:
};

22 thoughts to “【TopCoder SRM714】ParenthesisRemoval”

  1. I know this if off topic but I’m looking into starting my own blog and was
    wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% certain. Any tips or advice would be greatly appreciated.
    Cheers

  2. Howdy! This post could not be written any better! Reading through this post reminds
    me of my previous room mate! He always kept chatting
    about this. I will forward this page to him.
    Fairly certain he will have a good read. Thanks for sharing!

  3. Hey! I know this is kinda off topic however , I’d figured I’d ask.
    Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa?

    My blog goes over a lot of the same subjects as yours and I
    think we could greatly benefit from each other. If you are interested feel free
    to send me an e-mail. I look forward to hearing from you!
    Great blog by the way!

  4. Wow! This blog looks exactly like my old one! It’s on a totally
    different topic but it has pretty much the same page
    layout and design. Superb choice of colors!

  5. Good day! This is kind of off topic but I need some advice from an established blog.
    Is it very difficult to set up your own blog? I’m not very techincal but I
    can figure things out pretty quick. I’m thinking about setting up my own but I’m not sure where to begin. Do you have any points or
    suggestions? Appreciate it

  6. It’s truly very complicated in this full of activity life to listen news
    on Television, therefore I simply use web for that purpose, and obtain the most
    up-to-date news.

  7. Excellent web site. A lot of useful info here. I’m sending it to some friends ans additionally sharing in delicious.
    And naturally, thank you on your effort!

  8. Hey there! I know this is kind of off-topic however I had to ask.
    Does building a well-established blog such as yours take a large
    amount of work? I’m completely new to writing a blog but I do write in my
    journal everyday. I’d like to start a blog so I can share my experience and thoughts online.
    Please let me know if you have any suggestions or tips
    for new aspiring blog owners. Appreciate it!

  9. Every weekend i used to go to see this web site, for the reason that i wish for enjoyment, as this this
    site conations truly fastidious funny stuff too.

  10. Hi I am so grateful I found your web site, I really
    found you by error, while I was searching on Google
    for something else, Anyhow I am here now and would just like to say many thanks for
    a fantastic post and a all round thrilling blog (I also love the theme/design), I don’t have
    time to read it all at the moment but I have saved it and also added in your RSS feeds, so when I have time I will be back to read a great deal more,
    Please do keep up the awesome job.

  11. After examine just a few of the weblog posts in your website now, and I actually like your manner of blogging. I bookmarked it to my bookmark website record and shall be checking again soon. Pls take a look at my web site as nicely and let me know what you think.

Leave a Reply

Your email address will not be published. Required fields are marked *