Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings

                                                                                                           Yaroslav and Two Strings
                                                                                                      time limit per test  2 seconds
                                                                                                memory limit per test  256 megabytes
                                                                                                            input  standard input
                                                                                                             output standard output

Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s, similarly, wj represents the j-th digit of string w.

A string's template is a string that consists of digits and question marks ("?").

Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.

Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7).

Input

The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format.

Output

In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7).

Sample test(s)
Input
2
90
09
Output
1
Input
2
11
55
Output
0
Input
5
?????
?????
Output
993531194
Note

The first test contains no question marks and both strings are incomparable, so the answer is 1.

The second test has no question marks, but the given strings are comparable, so the answer is 0.

  看着题解想的:

    一道很好的组合题,正着想不好想,就倒着想,先弄出所有的情况 然后去掉不符合的情况。显然只是 >= 或<=的不符合要求,至于全部等于包含在上面这个不等式中,所有的情况减>= 然后在减<=  这样会多减一个全部等于的情况,再加上就行了。 
#include 
#include 
#include 
char s1[1000000],s2[1000000];
long long int a[100010],b[100010],c[100010],d[100010];
long long int sum1,sum2,sum3,sum4,res;
long long int mod=1000000007;
int main()
{
    int i,j,n,m,s,t;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s %s",s1,s2);
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        memset(d,0,sizeof(d));
        for(i=0;i<=n-1;i++)
        {
            if(s1[i]=='?'&&s2[i]=='?')
            {
                a[i]=100; b[i]=55; c[i]=55; d[i]=10;
            }else if(s1[i]=='?')
            {
                a[i]=10; b[i]=9-(s2[i]-'0')+1; c[i]=s2[i]-'0'+1; d[i]=1;
            }else if(s2[i]=='?')
            {
                a[i]=10; b[i]=s1[i]-'0'+1;  c[i]=9-(s1[i]-'0')+1; d[i]=1;
            }else if(s1[i]>s2[i])
            {
                a[i]=1; b[i]=1; c[i]=0; d[i]=0;
            }else if(s1[i]

你可能感兴趣的:(Codeforces)