Codeforces 296B Yaroslav and Strings dp+ (Getting Started

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions

Give the 2 number string s of length n, T (some positions are?)

How many kinds of filling methods make S[i]>t[i] && S[j] <t[j]

Ideas:

First find out that ans means all filling methods, ans = 10^num, num is a total number of 2 strings

Dp[0][i] Indicates the number of fill schemes with length I and for any J (1<=j<=i) satisfying s[j]<=t[j]

Dp[1][i] = S[j]==t[j]

Dp[2[i] = S[j]>=t[j]

The answer = Ans-dp[0][n]-dp[1][n] + dp[2][n];



#include <bits/stdc++.h>const int inf = 1e8;const double eps = 1e-8;const double pi = ACOs ( -1.0); const int mod = 1e9+      7;template <class t> inline BOOL Rd (T &ret) {char c; int sgn;      if (C=getchar (), c==eof) return 0; while (c!= '-' && (c< ' 0 ' | |      C> ' 9 ')) C=getchar ();      sgn= (c== '-')? -1:1;      ret= (c== '-')? 0: (c ' 0 ');      while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 ');      RET*=SGN;  return 1;      } template <class t> inline void pt (T x) {if (x <0) {Putchar ('-'); x =-X;}      if (x>9) pt (X/10);  Putchar (x%10+ ' 0 '); }using namespace Std;typedef Long long ll;typedef pair<int,int> pii;const int N = 1e5+10;int N;char s[2][n];ll dp[3] [N];void Mul (ll &x, ll y) {x = (x*y)%mod;} void Add (ll &x, ll y) {x = (x+y)%mod;}        int main () {while (cin>>n) {scanf ("%s", s[0]+1);                scanf ("%s", s[1]+1);        ll ans = 1;        for (int i = 0; i < 3; i++) dp[i][0] = 1; ll A, B, C            for (int i = 1; I <= n; i++) {if (s[0][i] = = '? ' && s[1][i] = = '? ')                {a = c = n; b = 10;            Mul (ans, 100);            } else if (s[0][i] = = '? ')                {Mul (ans, 10);                A = s[1][i]-' 0 ';                b = 1;            c = 9-a;            } else if (s[1][i] = = '? ')                {Mul (ans, 10);                c = s[0][i]-' 0 ';                b = 1;            A = 9-c;                } else {a = s[0][i]<s[1][i];                b = S[0][i]==s[1][i];            c = s[0][i]>s[1][i];            } Dp[0][i] = dp[0][i-1]* (a+b)%mod;            Dp[1][i] = Dp[1][i-1]*b%mod;        Dp[2][i] = dp[2][i-1]* (b+c)%mod;        } ans-= dp[0][n];        Ans-= dp[2][n];        Ans + = dp[1][n];        Ans%= MoD;        if (ans<0) Add (ans, mod); PT (ANS%MOD);    Puts (""); } return 0;}


Codeforces 296B Yaroslav and Strings dp+ (Getting Started

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.