1、我感觉自己有两个不足,一个是DP水平,一个是C++水平,像标程中用的auto就非常巧妙。。。还有标程对STL的使用非常熟练,可我几乎不行。。。还要努力。
2、刚开始毫无头绪,看了标程后才知道应该按顺序去考虑,来设计方程,而不是让思维无序化。其实要是真的对语言熟悉、按顺序考虑,我还不一定做不出来呢。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
class AlienAndSetDiv2 {
public:
int K;
const int MOD=1000000007;
typedef set<int,greater<int> > gset;
map<gset,long> dp[101];
long rec(int n,gset unmatched){
auto q=dp[n].find(unmatched);
long res=0;
if(q==dp[n].end()){
if(n==0){
if(unmatched.size()==0) res=1;
}else{
if(unmatched.size()==0){
res+=(2*rec(n-1,{n}))%MOD;
}else{
int mx=*unmatched.begin();
gset newset=unmatched;
newset.erase(newset.begin());
res+=rec(n-1,newset);
if(mx!=n+K){
newset=unmatched;
newset.insert(n);
res+=rec(n-1,newset);
}
}
res%=MOD;
}
dp[n][unmatched]=res;
}else{
res=q->second;
}
return res;
}
int getNumber(int N, int K) {
this->K=K;
return rec(2*N,{});
}
};