307712: CF1400F. x-prime Substrings
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
x-prime Substrings
题意翻译
给定一个数字字符串$s$,定义$f(l,r)$为$s_l,s_{l+1},\cdots,s_{r}$的数字和。 定义一个区间$[l,r]$是$x-prime$的,当且仅当满足如下条件: - $f(l,r)=x$ - 不存在$[l,r]$的子区间$[l_2,r_2]$,使得$f(l_2,r_2)$是$x$的**真因数**。 求最少要删除$s$中的字符个数,使得删除后的$s$不存在$x-prime$区间。 $1\le |s|\le 1000$,$1\le x\le 20$。题目描述
You are given an integer value $ x $ and a string $ s $ consisting of digits from $ 1 $ to $ 9 $ inclusive. A substring of a string is a contiguous subsequence of that string. Let $ f(l, r) $ be the sum of digits of a substring $ s[l..r] $ . Let's call substring $ s[l_1..r_1] $ $ x $ -prime if - $ f(l_1, r_1) = x $ ; - there are no values $ l_2, r_2 $ such that - $ l_1 \le l_2 \le r_2 \le r_1 $ ; - $ f(l_2, r_2) \neq x $ ; - $ x $ is divisible by $ f(l_2, r_2) $ . You are allowed to erase some characters from the string. If you erase a character, the two resulting parts of the string are concatenated without changing their order. What is the minimum number of characters you should erase from the string so that there are no $ x $ -prime substrings in it? If there are no $ x $ -prime substrings in the given string $ s $ , then print $ 0 $ .输入输出格式
输入格式
The first line contains a string $ s $ ( $ 1 \le |s| \le 1000 $ ). $ s $ contains only digits from $ 1 $ to $ 9 $ inclusive. The second line contains an integer $ x $ ( $ 1 \le x \le 20 $ ).
输出格式
Print a single integer — the minimum number of characters you should erase from the string so that there are no $ x $ -prime substrings in it. If there are no $ x $ -prime substrings in the given string $ s $ , then print $ 0 $ .
输入输出样例
输入样例 #1
116285317
8
输出样例 #1
2
输入样例 #2
314159265359
1
输出样例 #2
2
输入样例 #3
13
13
输出样例 #3
0
输入样例 #4
3434343434
7
输出样例 #4
5