首页 > 试题广场 >

小苯的计算式

[编程题]小苯的计算式
  • 热度指数:1334 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
小苯有一个长度为 n 的字符串,其是一个两非负整数加法运算的式子,形如:A+B=C

现在小苯只记得这个式子的结果 C,以及式子的长度 n

请你帮小苯数一数,总共有多少个不同的符合条件的这种式子呢。
(注意:A, B, C 都是不含前导零的。)

输入描述:
输入包含一行两个正整数 n, C\ (5 \leq n \leq 20),\ (1 \leq C \leq 200000)。分别表示计算式的长度,以及计算式的结果值。


输出描述:
输出一行一个整数,表示不同的符合条件的计算式个数。
示例1

输入

5 2

输出

3

说明

长度为 5 的,运算结果为 2 的,只包含非负整数的不同运算式有:
0+2=2
1+1=2
2+0=2
这三个。

备注:
小苯认为两个计算式 s1, s2 不同:当且仅当 s1, s2 长度不相同,或两者长度相同均为 n 时,存在一个 i\ (1 \leq i \leq n),使得 s1_i \ne s2_i
头像 drawer
发表于 2025-11-21 09:49:04
//暴力,纯纯暴力,直接0,c遍历一遍就完了 void solve() { int n, c; cin >> n >> c; int csize = to_string(c).size(); int absize = n - 2 - csize; 展开全文
头像 Skyzhou
发表于 2025-11-21 00:43:51
考虑题目数据范围很小,直接暴力即可😋 #include <bits/stdc++.h> #define MAXN 1000010 #define LL long long #define INF 0x7fffffff using namespace std; const LL MOD 展开全文
头像 此在Dasein
发表于 2025-11-21 02:45:05
算法思路分析 问题理解 需要统计满足 A+B=C 且字符串总长度为 n 的不同算式数量 核心约束:A、B、C 均无前导零(数值为0时长度为1) 字符串格式:A的十进制 + + + B的十进制 + = + C的十进制 总长度:len(A) + len(B) + len(C) + 2 = n 关键观 展开全文
头像 Xiaotu666
发表于 2025-11-21 10:35:45
//暴力 #include <bits/stdc++.h> using namespace std; #define int long long #define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.ti 展开全文
头像 哈哈哈哈和哈哈哈哈
发表于 2025-11-21 12:04:09
#include <bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; int z=to_string(m).size(); n-=2+z; int 展开全文
头像 Kato_Shoko
发表于 2025-11-21 12:25:01
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N =1e6+5, mod = 1e9 + 7, inf = 5e18; int n,c; void solve(){ 展开全文
头像 bing糖雪狸
发表于 2025-11-21 16:23:15
#include <bits/stdc++.h> #define il inline using namespace std; #define pb push_back #define fastio \ ios::sync_with_stdi 展开全文
头像 自由的风0450
发表于 2025-11-21 17:25:19
#include <iostream> #include<cmath> #include<string> using namespace std; int count(int n,int c){ string t=to_string(c); in 展开全文
头像 WindsWhisper
发表于 2025-11-21 20:11:27
#include <iostream> using namespace std; int sh(int a){ if(a==0) return 1; int d=0; while(a>0){ a=a/10; d++; 展开全文