H. Roman and Numbers(状态压缩dp)

题目链接:http://codeforces.com/group/NVaJtLaLjS/contest/239876/problem/H

题目大意:给你一个数n,m要求把n的每一位排列组合,第一个数不能为0的方案有多少种。

思路:状态压缩。dp[i][j] i表示所取的数的集合,j表示在模m的意义下有多少种方案,注意最后要除以重复出现的数的阶乘。

代码:

#include
using namespace std;

typedef long long ll;
const int maxn = 1e5+7;
ll dp[(1<<18)+7][150];
ll bits[20];
ll n,m;
ll jic[20] = {1,1};
ll inv[20] = {0};

int main(){
	cin >> n >> m;
	ll now = n;
	int len = 0;
	for(int i = 2;i <= 18; i++){
		jic[i] = i*jic[i-1];
	}
	while(now){
		inv[now%10]++;
		bits[len++] = now%10;
		now /= 10;
	}
	dp[0][0] = 1;
	for(int i = 0;i < (1<

 

你可能感兴趣的:(动态规划--状压dp)