自己憋了N久也没思路,看了一下别人的代码,神呀,这就是差距呀,继续努力。
代码:
#include<iostream> #include<cstring> #include<cstdio> #include<string> #include<set> #include<map> #include<cmath> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<stack> //#define ull unsigned long long #define ll long long using namespace std; const int INF=0x3f3f3f3f; const int MOD=1000003; const int N=15; int dp0[1<<N],dp1[1<<N]; class SetOfPatterns { public: int howMany(vector <string> p, int k) { int n=p.size(); int m=p[0].size(); memset(dp0,0,sizeof(dp0)); dp0[(1<<n)-1]=1; for(int i=0;i<m;++i) { memset(dp1,0,sizeof(dp1)); for(char c='a';c<='z';++c) { int k=0; for(int j=0;j<n;++j) { if(p[j][i]==c||p[j][i]=='?') k=(k|(1<<j)); } for(int i=0;i<(1<<n);++i) { dp1[i&k]=(dp1[i&k]+dp0[i])%MOD; } } memcpy(dp0,dp1,sizeof(dp0)); } int sum=0; for(int i=0;i<(1<<n);++i) if(__builtin_popcount(i)==k) sum=(sum+dp0[i])%MOD; return sum; } };