XJOI 傳送(線性篩數論函數,dp)
阿新 • • 發佈:2017-09-07
mes col pad img es2017 png cstring char wid
這題就是篩了一個除數函數,沒什麽好說的
#include<cstdio> #include<cstring> #include<cstdlib> using namespace std; const int N=21,M=1e9+7; char mp[N][N]; int f[1<<20],n,kk,ans,mx; int calc(int x){ int res=0; while (x){ if (x&1) res++; x>>=1; }return res; } int main(){ scanf("%d%d",&n,&kk); for (int i=1; i<=n; i++) scanf("%s",mp[i]+1); mx=(1<<n)-1; f[0]=1; for (int i=1; i<=n; i++) for (int k=mx; k>=0; k--) for (int j=1; j<=n; j++) if (mp[i][j]==‘#‘&&((k>>j-1)&1)==0) f[k|(1<<j-1)]=(f[k|(1<<j-1)]+f[k])%M; for (int k=0; k<=mx; k++) if (calc(k)==kk) ans=(ans+f[k])%M; printf("%d",ans); }
XJOI 傳送(線性篩數論函數,dp)