[原创]UVALive - 7344 Numbered Cards [数位dp+状压dp]【动态规划】
[原创]UVALive - 7344 Numbered Cards [数位dp+状压dp]【动态规划】
2017-07-05 22:42:33 Tabris_ 阅读数:382
博客爬取于2020-06-14 22:39:44
以下为正文
版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/74505041
题目链接:https://cn.vjudge.net/problem/UVALive-7344
——————————————————————————————————————————
You have N cards and each has an unique number between 1 and N written on it. In how many
ways can you select a non-empty subset of the cards such that the number written on any two of your selected cards don’t have any common digits?
For example, when N = 12, {1, 2, 3}, {2, 11}, {3, 4, 5, 6, 7, 8, 9, 12} are some valid selections. But
{1, 2, 10}, {2, 5, 12} are not allowed.
Input
The first line of the input contains an integer T which is the number of test cases. Each of
the following T lines denote a test case, containing an integer N.
Output
For each test case, output the case number followed by the number of subsets modulo 1000000007.
Sample Input
2
3
12
Sample Output
Case 1: 7
Case 2: 1151
————————————————————————————————————————————
题目大意:
让你在[1,N]内选择一些数构成一个集合,使得集合中任意两个数没有相同的数字,(但一个数可以由相同的数字比如11.22),问你合法的集合的个数
首先能确定的是集合中数最多不超过10个,那么可以枚举来
先选择一个,在选择第二个,保证其两者不没有相同位即可
显然这个过程是可以进行dp的
用长度为10的二进制表示0~9.然后进行转移即可
设dp[i][j],表示取到第i个数是选择了j(二进制)对应的这些数字
从而有dp[i][j]=\displaystyle \sum dp[i-1][k]*A(表示k\xor j这个状态下的数的个数)
显然有一个O(1010241024)即可
但是对于A(表示k\xor j这个状态下的数的个数)我们应该怎么求呢
显然是预处理啊 ,
通过数位dp进行统计,预处理出每种状态下的数的个数。
附本题代码
————————————————————————————————————————————
1 | LL dp_nex[15][(1<<12)]; |