Restore Calculation - HUN dp

本文探讨了一种解决动物学校算术修复问题的方法,即在给定的数学表达式中替换缺失的数字,使等式成立。通过使用多层循环和动态规划,我们能够计算出所有可能的解决方案的数量,并对输入进行处理以确保符合数学规则。此外,文章还提供了一个程序实现的示例,展示了如何通过编程来解决此类问题。

http://acm.hnu.cn/online/?action=problem&type=show&id=12813&courseid=267

Restore Calculation
Time Limit: 20000ms, Special Time Limit:50000ms, Memory Limit:65536KB
Total submit users: 19, Accepted users: 17
Problem 12813 : No special judgement
Problem description

The Animal School is a primary school for animal children. You are a fox attending this school.

One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako. Arithmetical Restorations are the problems like the following:

  • You are given three positive integers, AB and C.

  • Several digits in these numbers have been erased.

  • You should assign a digit in each blank position so that the numbers satisfy the formula A+B=C.

  • The first digit of each number must not be zero. It is also the same for single-digit numbers.

You are clever in mathematics, so you immediately solved this problem. Furthermore, you decided to think of a more difficult problem, to calculate the number of possible assignments to the given Arithmetical Restorations problem. If you can solve this difficult problem, you will get a good grade.

Shortly after beginning the new task, you noticed that there may be too many possible assignments to enumerate by hand. So, being the best programmer in the school as well, you are now trying to write a program to count the number of possible assignments to Arithmetical Restoration problems.


Input

The input is a sequence of datasets. The number of datasets is less than 100. Each dataset is formatted as follows.

A
B
C

Each dataset consists of three strings, AB and C. They indicate that the sum of A and B should be C. Each string consists of digits (0-9) and/or question mark (?). A question mark (?) indicates an erased digit. You may assume that the first character of each string is not 0 and each dataset has at least one ?.

It is guaranteed that each string contains between 1 and 50 characters, inclusive. You can also assume that the lengths of three strings are equal.

The end of input is indicated by a line with a single zero.


Output

For each dataset, output the number of possible assignments to the given problem modulo 1,000,000,007. Note that there may be no way to solve the given problems because Ms. Hanako is a careless rabbit.


Sample Input
3?4
12?
5?6
?2?4
5?7?
?9?2
?????
?????
?????
0
Sample Output
2
40
200039979
Judge Tips

The answer of the first dataset is 2. They are shown below.

  • 384 + 122 = 506

  • 394 + 122 = 516


题意:一共有多少种可以成立的方法。

思路:三重for循环,dp[i][0]表示从右往左第i位不进位的情况数量,dp[i][1]表示仅为的情况数量。

AC代码如下:

#include<cstdio>
#include<cstring>
using namespace std;
char s[4][100];
int num[4][100][2];
long long dp[100][2],M=1000000007;
int main()
{ int i,j,k,len,a,b,c,num1,num2,num3,num4,p1,p2,p3;
  while(~scanf("%s",s[1]))
  { if(s[1][0]=='0')
     break;
    len=strlen(s[1]);
    scanf("%s",s[2]);
    scanf("%s",s[3]);
    for(i=1;i<=3;i++)
    { for(j=2;j<=len;j++)
       if(s[i][j-1]=='?')
       { num[i][j][0]=0;
         num[i][j][1]=9;
       }
       else
       { num[i][j][0]=s[i][j-1]-'0';
         num[i][j][1]=s[i][j-1]-'0';
       }
      if(s[i][0]=='?')
       { num[i][1][0]=1;
         num[i][1][1]=9;
       }
       else
       { num[i][1][0]=s[i][1-1]-'0';
         num[i][1][1]=s[i][1-1]-'0';
       }
    }
    memset(dp,0,sizeof(dp));
    dp[len+1][0]=1;
    for(i=len;i>=1;i--)
    { num1=0;num2=0;num3=0,num4=0;
      for(a=num[1][i][0];a<=num[1][i][1];a++)
       for(b=num[2][i][0];b<=num[2][i][1];b++)
        for(c=num[3][i][0];c<=num[3][i][1];c++)
        {    if((a+b)%10==c)
             { if(a+b<10)
                num1++;
               else
                num2++;
             }
             if((a+b+1)%10==c)
             { if(a+b+1<10)
                num3++;
               else
                num4++;
             }
        }
          dp[i][0]=(dp[i+1][0]*num1+dp[i+1][1]*num3)%M;;
          dp[i][1]=(dp[i+1][0]*num2+dp[i+1][1]*num4)%M;
    }
    printf("%I64d\n",dp[1][0]);
  }
}



多源数据接入 支持校园各业务系统数据接入:包括教务系统(学生成绩、课程信息)、学工系统(奖惩记录、资助信息)、后勤系统(宿舍分配、能耗数据)、图书馆系统(借阅记录、馆藏信息)、一卡通系统(消费数据、门禁记录)等。 接入方式:提供数据库直连(MySQL、SQL Server)、文件导入(CSV、Excel、JSON)、API 接口调用等多种方式,支持实时同步与定时批量同步。 数据标准化与治理 建立校园数据标准体系:统一数据格式(如日期格式、学号编码规则)、定义核心数据元(如 “学生” 包含学号、姓名、专业等必选字段)、规范代码集(如性别代码 “1 - 男,2 - 女”)。 数据清洗:自动检测并处理缺失值、重复值、异常值(如成绩 > 100 分),通过规则引擎实现数据校验(如 “学生年龄需在 16-30 岁之间”)。 元数据管理:记录数据来源、格式、更新频率、负责人等信息,生成数据血缘图谱,追踪数据从产生到应用的全生命周期。 二、数据共享与交换核心功能 分布式数据存储 基于 Hadoop HDFS 实现海量数据存储:结构化数据(成绩、消费记录)存入 HBase,非结构化数据(文档、图片、视频)直接存储于 HDFS,日志类数据通过 Flume 采集至 HDFS。 支持数据分片与副本机制,确保数据高可用(默认 3 副本存储),满足校园 PB 级数据存储需求。 数据交换引擎 构建点对点数据交换通道:各部门系统可通过交换引擎向平台上传数据或申请获取授权数据,支持同步 / 异步交换模式。 交换流程管理:定义数据交换规则(如 “学工系统每日向平台同步新增学生信息”),记录交换日志(成功 / 失败状态、数据量),失败时自动重试。 数据脱敏:对敏感数据(如身份证号、银行卡号)在交换过程中进行脱敏处理(如显示 “110********5678”),兼顾共享与隐私保护。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值