Codeforces Round #785 (Div. 2) C. Palindrome Basis
思路:我们很容易想到先筛去回文数,然后就变成完全背包求方案数裸题了
#include<vector> #include<iostream> #include<string> #include<algorithm> using namespace std; int main() { vector<int> dp(40009,0); vector<int> hw; for(int i=1;i<=40000;i++){ string s=to_string(i); string t=s; reverse(t.begin(),t.end()); if(s==t) hw.push_back(i); } dp[0]=1; int len=hw.size(); for(int i=0;i<len;i++){ int v=hw[i]; for(int j=v;j<=40000;j++){ dp[j]=(dp[j]+dp[j-v])%1000000007; } } int time;cin>>time; while(time--){ int temp;cin>>temp; cout<<dp[temp]<<endl; } }