题目
以为是第二类斯特林数,太逆天了。虽然确实是,但是没必要这么做。而且这么做了还没做对更lao了。
题意: 给定长度为n的非负整数数组a,和为m,要使得数组的异或最大,有多少种方案。
思路: 把m二进制拆解,每有一个数就乘n。因为这一位可以放到数组的任意一个位置,而且互相之间莫得冲突。就可以下班了。
当时想的很复杂,想着是把m对应的二进制位放入一个数、两个数。然后寄了。也可以用第二类斯特林数解决,相当于把m对应的cnt个二进制位放入n个相同的盒子里。然后枚举把cnt个二进制位放到1、2…min(cnt,n)个数里.
时间复杂度: O(logm) 或 O(logm * logm)
代码:
// Problem: 小沙的数数
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/23477/H
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round() 四舍五入 ceil() 向上取整 floor() 向下取整
// lower_bound(a.begin(),a.end(),tmp,greater<ll>()) 第一个小于等于的
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){ return x&(-x);}
template<typename T>void write(T x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
#define int long long
int n,m,k,T;
void solve()
{
read(n); read(m);
int ans = 1;
n %= mod;
while(m)
{
if(m & 1)
{
ans = ans * n % mod;
}
m /= 2;
}
ans = (ans + mod) % mod;
cout<<(ans % mod);
// cout<<"\n"<<mod<<endl;
}
signed main(void)
{
T = 1;
// OldTomato; cin>>T;
// read(T);
while(T--)
{
solve();
}
return 0;
}
// Problem: 小沙的数数
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/23477/H
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round() 四舍五入 ceil() 向上取整 floor() 向下取整
// lower_bound(a.begin(),a.end(),tmp,greater<ll>()) 第一个小于等于的
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 62;
const int M = 1e6+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){ return x&(-x);}
template<typename T>void write(T x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
#define int long long
int n,m,k,T;
int f[N][N];//f[n][m] = f[n-1][m-1] + m * f[n-1][m]
void init()
{
f[1][1] = 1;
for(int i=2;i<N;++i)
{
for(int j=1;j<N;++j)
{
f[i][j] = (f[i-1][j-1] + j * f[i-1][j] % mod) % mod;
}
}
}
int fun(int x)
{
int res = 0;
while(x)
{
if(x & 1) res ++ ;
x >>= 1;
}
return res;
}
int qpow(int a,int k)
{
int res = 1;
while(k)
{
if(k & 1) res = res * a % mod;
a = a * a % mod;
k >>= 1;
}
return res;
}
int fac(int n)
{
int res = 1;
for(int i=2;i<=n;++i)
{
res = res * i % mod;
}
return res;
}
int ni(int x)
{
return qpow(x,mod-2);
}
int C(int n,int m)
{
int res = 1;
for(int i=n-m+1;i<=n;++i)
{
res = res * (i%mod) % mod;
}
for(int i=1;i<=m;++i)
{
res = res * ni(i) % mod;
}
return res;
}
void solve()
{
read(n); read(m);
if(m == 0)
{
write(1); return;
}
init();
int cnt = fun(m);
int ans = 0;
for(int i=1;i<=min(cnt,n);++i)
{
ans = (ans + C(n,i) * fac(i) % mod * f[cnt][i] % mod ) % mod;
}
ans = (ans + mod) % mod;
write(ans);
}
signed main(void)
{
T = 1;
// OldTomato; cin>>T;
// read(T);
while(T--)
{
solve();
}
return 0;
}