fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ____AnhKietSS____ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define ll long long
  6. #define fi first
  7. #define se second
  8. #define pb push_back
  9. #define ii pair<int,int>
  10. #define foru(i,a,b) for(int i=(a);i<=(b);i++)
  11. #define ford(i,a,b) for(int i=(a);i>=(b);i--)
  12.  
  13. const ll MOD=1000000007;
  14.  
  15. int n,m;
  16. int a[25],b[25];
  17. int k;
  18. ll dp[1<<20][11];
  19.  
  20. signed main()
  21. {
  22. ____AnhKietSS____
  23.  
  24. freopen("game11.inp","r",stdin);
  25. freopen("game11.out","w",stdout);
  26.  
  27. cin>>n>>m;
  28.  
  29. vector<int> d(n+1,0);
  30.  
  31. int r=0;
  32.  
  33. foru(i,1,m)
  34. {
  35. cin>>a[i];
  36. d[a[i]]=1;
  37. r=(r*10+a[i])%11;
  38. }
  39.  
  40. foru(i,1,n)
  41. {
  42. if(!d[i])
  43. {
  44. b[k]=i;
  45. k++;
  46. }
  47. }
  48.  
  49. dp[0][r]=1;
  50.  
  51. int lim=(1<<k);
  52.  
  53. for(int mask=0;mask<lim;mask++)
  54. {
  55. for(int x=0;x<11;x++)
  56. {
  57. if(dp[mask][x]==0) continue;
  58.  
  59. for(int i=0;i<k;i++)
  60. {
  61. if(mask&(1<<i)) continue;
  62.  
  63. int nmask=mask|(1<<i);
  64. int nr=(x*10+b[i])%11;
  65.  
  66. dp[nmask][nr]+=dp[mask][x];
  67. dp[nmask][nr]%=MOD;
  68. }
  69. }
  70. }
  71.  
  72. cout<<dp[lim-1][0];
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty