Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
来源:互联网 发布:立花宗茂 知乎 编辑:程序博客网 时间:2024/05/18 21:07
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 andsj < wj. Here signsi represents thei-th digit of string s, similarly, wj represents thej-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 by1000000007 (109 + 7).
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 equalsn. The third line contains the second template in the same format.
In a single line print the remainder after dividing the answer to the problem by number1000000007 (109 + 7).
29009
1
21155
0
5??????????
993531194
The first test contains no question marks and both strings are incomparable, so the answer is1.
The second test has no question marks, but the given strings are comparable, so the answer is0.
看着题解想的:
#include <stdio.h>#include <math.h>#include <string.h>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]<s2[i]) { a[i]=1; b[i]=0; c[i]=1; d[i]=0; }else { a[i]=1; b[i]=1; c[i]=1; d[i]=1; } } sum1=sum2=sum3=sum4=1; for(i=0;i<=n-1;i++) { sum1=(sum1*a[i])%mod; sum2=(sum2*b[i])%mod; sum3=(sum3*c[i])%mod; sum4=(sum4*d[i])%mod; } res=(sum1-sum2-sum3+sum4)%mod; if(res<0) { res+=mod; } printf("%lld\n",res); } return 0;}
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- Codeforces Round #179 (Div. 2) B (codeforces 296b) Yaroslav and Two Strings
- CodeForces Round #179 (296B) - Yaroslav and Two Strings
- CodeForces 296B Yaroslav and Two Strings (容斥)
- Codeforces Round #226 (Div. 2) B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces Round #226 (Div. 2)B. Bear and Strings
- Codeforces 296B Yaroslav and Two Strings dp+容斥(入门
- Codeforces Round #290(Div.2) B.Fox And Two Dots
- B. Fox And Two Dots( Codeforces Round #290 (Div. 2))
- B. Fox And Two Dots Codeforces Round #290 (Div. 2)
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots
- Codeforces Round #138 (Div. 1), problem: (B) Two Strings
- Codeforces Round #182 (Div. 1) D. Yaroslav and Divisors
- Codeforces Round #182 (Div. 1)D. Yaroslav and Divisors
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- linux 下makefile编译C++工程
- 解决 Weblogic Proxy 服务器中文乱码的问题
- nginx代理配置注意事项
- 融资融券交易
- Head First 设计模式 (八) 模版方法模式(Template method pattern) C++实现
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings
- C语言中全局变量初始化的重要性!!!
- 判断出栈序列是否正确
- Android数据存储——2.文件存储_F_解析JSON文档
- Oracle表空间相关
- IOS-Block编程
- Stop the Hollyweb! No DRM in HTML5
- 关于AD芯片采样时序的说明
- ,CFormView::Create()里,_AfxCheckDialogTemplate输出Cannot find dialog template with IDD 0x00AB