Digits Parade

題意:一個字符串S,每個字符是數字(0到9)或'?'(半角)。
我們用數字(0 ~ 9)替換'?', 可以得到整數A,那麼請問有多少種情況可以滿足A除以13餘5 
A可能有前導0

Sample Input 3

Copy

7?4

Sample Output 3

Copy

0

We may not be able to produce an integer satisfying the condition.


Sample Input 4

Copy

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

Copy

153716888

這個最優解肯定是dp,但是難點在於如何使用,來構造這個過程,emmmm,簡單來說就是模擬除法的運算。。。

看代碼吧。

​
#include <iostream>
#include <cstring>
# define mod 1000000007
using namespace std;
typedef long long ll;
ll dp[100009][13];
int main(){
	string s;
	cin>>s;
	memset(dp,0,sizeof(dp));
	if(s[0]=='?')
		for(int i=0;i<10;i++)
			dp[0][i]=1;
	else
		dp[0][s[0]-'0']=1;
		int len=s.length();
	for(int i=1;i<len;i++)
	{
		if(s[i]=='?')
		{
			for(int j=0;j<13;j++)
				for(int k=0;k<10;k++)
				{
					dp[i][(j*10+k)%13]+=dp[i-1][j];
					dp[i][(j*10+k)%13]%=mod;
				}
		}
		else
		{
			for(int j=0;j<13;j++)
			{
				dp[i][(s[i]-'0'+j*10)%13]+=dp[i-1][j];
				dp[i][(s[i]-'0'+j*10)%13]%=mod;
			}
		}
	}
		 cout<<dp[len-1][5]<<endl;
	return 0;
} 

​

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章