CSU 1374: Restore Calculation
来源:互联网 发布:电脑怎么截图淘宝客服 编辑:程序博客网 时间:2024/05/22 02:34
题意:
就是输入三行数据,使得第一行的数据加上第二行的数据等于第三行的。每组数据可能会有'?',代表一个未知的数,每个?代表的数字可以不一样,每行最多有50个字符,首字符不可为0。计算总共有多少种可能。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
using namespace std;
const int mod=1e9+7;
const int maxn=60;
char ch1[maxn],ch2[maxn],ch3[maxn];
int dp[maxn][2];
int main()
{
//freopen("test.txt","r",stdin);
while(scanf("%s",ch1)&&ch1[0]!='0')
{
scanf("%s",ch2);
scanf("%s",ch3);
memset(dp,0,sizeof(dp));
int len=strlen(ch1);
dp[len][0]=1; //为什么初始化这个没搞懂
int i,j,k,l,s,m;
for(i=len-1;i>=0;i--)
{
for(j=(i)?0:1;j<10;j++) //i=0 j=1
{
if(ch1[i]-'0'!=j&&ch1[i]!='?') continue;
for(k=(i)?0:1;k<10;k++)
{
if(ch2[i]-'0'!=k&&ch2[i]!='?') continue;
for(l=0;l<2;l++)
{
s=(j+k+l)/10; m=(j+k+l)%10;
if(m==ch3[i]-'0'||ch3[i]=='?')
dp[i][s]=(dp[i+1][l]+dp[i][s])%mod; //这个式子!!!
}
}
}
}
cout<<dp[0][0]<<endl;
}//while
return 0;
}
- CSU 1374: Restore Calculation
- CSU 1374 Restore Calculation(数位dp)
- Restore Calculation - HUN dp
- HNU 12813 Restore Calculation
- 湖大训练赛1 Restore Calculation
- HOJ 12813 Restore Calculation(数位DP)
- Calculation
- Restore
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- Android 游戏设计教程:游戏元素和工具
- assert.h c++
- dijkstra,bellman-ford,floyd,HDU—1874 畅通工程续
- SQL 触发器
- getParameter的用法总结
- CSU 1374: Restore Calculation
- 使用JAXB实现JAVA对象和XML字符串的互相转换实例
- 1.JavaWeb基础 最出色的解析工具:DOM4J
- 在Android X86上执行Native ARM 代码---Android X86应用兼容的探讨
- Python 练习代码 -- 异常,抛异常, 自定义异常
- qt
- 今天开始学习Python
- 深入浅出 Java Concurrency (J.U.C)
- uva-10038- Jolly Jumper