SRM 605 AlienAndSetDiv2

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,{});
 }
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值