Go: package main

import "fmt"

func main() {
	//部屋を生成
	var H int

	fmt.Scan(&H)
	room := [][4]bool{}

	for i := 0; i < H; i++ {
		room = append(room, [4]bool{})
	}

	//荷物のおけない区画を設定
	var N int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		room[y][x] = true //ものがある状態を真とする
	}
	//荷物を配置
	var count int
	for i := 0; i < 3; i++ {
		for j := 0; j < H-1; j++ {
			if !room[j][i] && !room[j+1][i] && !room[j][i+1] && !room[j+1][i+1] {
				room[j][i] = true
				room[j+1][i] = true
				room[j][i+1] = true
				room[j+1][i+1] = true
				count++
			}
		}
	}
	fmt.Println(count)
}

C++: //#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;

int main() {

    int dp[10003][1<<5] = {{}};
    int block[10003] = {};

    int H,N;
    int x,y;
    scanf("%d %d", &H,&N );
    for (int i = 0; i < N; i++){
        scanf("%d %d", &x,&y );
        block[y] |= 1<<x;
    }

    int set[5] = {0xf,0x3,0x6,0xc,0x0};
    int vul[5] = {2, 1, 1, 1, 0};
    for (int ai = 0; ai < H-1; ai++){
        for (int bi = 0; bi < 1<<5; bi++){
            for (int si = 0; si < 5; si++){
                if( set[si] & (block[ai] | block[ai+1] | bi ) ){
                    continue;
                }
                dp[ai+1][set[si]] = max(dp[ai+1][set[si]] , dp[ai][bi] + vul[si] );
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < 1<<5; i++){
        ans = max(ans , dp[H-1][i] );
    }

    printf ("%d\n", ans);


    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

bool a[4][10001];//1 ????????????0 ????????????
int dp[10000][16];//i????????§?????????i+1????????§??????????????¨?????????1
int x[4]={0,1,2,0};
int y[4]={2,3,4,4};
signed main(){
	fill(dp[0],dp[0]+16,-(1<<29));
	int h,n;cin>>h>>n;
	memset(a,true,sizeof(a));
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		::a[a][b]=false;
		}
	dp[0][15]=0;
	for(int i=0;i<4;i++){
		int bit=15;
		bool OK=true;
		for(int j=x[i];j<y[i];j++){
			if(!a[j][0]||!a[j][1]){
						OK=false;
						}
					
				bit-=(1<<j);	
			}
		if(OK){dp[0][bit]=(y[i]-x[i])/2;}	
		}
	for(int i=0;i<h-1;i++){
		for(int j=0;j<16;j++){
			dp[i+1][15]=max(dp[i+1][15],dp[i][j]);
			for(int k=0;k<4;k++){
				bool OK=true;
				for(int l=x[k];l<y[k];l++){
					if(!a[l][i+1]||!a[l][i+2]||(j&(1<<l))==0){
						OK=false;
						}
					}
				if(OK){
					int bit=15;
					for(int l=x[k];l<y[k];l++){
						bit-=(1<<l);
						}
					dp[i+1][bit]=max(dp[i+1][bit],dp[i][j]+(y[k]-x[k])/2);	
					}	
				}
			}
		}
	cout<<*max_element(dp[h-2],dp[h-2]+16)<<endl;		
	}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///


int f[4][11234];
int h;
int n;

int dp[11234][1 << 3];

int check(int y, int x) {
  for(int i = y; i <= y + 1; i++) for(int j = x; j <= x + 1; j++) {
    if(f[j][i]) return 0;
  }
  return 1;
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> h;
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    f[x][y] = 1;
  }
  
  int ans = 0;
  {
    int y = 0;
    for(int i = 0; i < (1 << 3); i++) {
      int cnt = 0, no = 0;
      for(int ii = 0; ii < 3; ii++) if(i & (1 << ii)) {
        if(!check(y, ii)) no = 1;
        cnt++;
      }
      if(__builtin_popcount(i) >= 2) if(i != 5) no = 1; 
      if(no) continue;
      dp[y][i] = cnt;
      dump(y, i, cnt);
      ans = max(ans, dp[y][j]);
    }
  }

  for(int y = 0; y < h - 2; y++) {
    // yでの置き方
    for(int i = 0; i < (1 << 3); i++) {
      int no = 0;
      for(int ii = 0; ii < 3; ii++) if(i & (1 << ii)) {
        if(!check(y, ii)) no = 1;
      }
      if(__builtin_popcount(i) >= 2) if(i != 5) no = 1; 
      if(no) continue;
      // y + 1での置き方
      for(int j = 0; j < (1 << 3); j++) {
        int cnt = 0, no = 0;
        for(int ii = 0; ii < 3; ii++) if(j & (1 << ii)) {
          if(!check(y + 1, ii)) no = 1;
          cnt++;
        }
        if(__builtin_popcount(j) >= 2) if(j != 5) no = 1; 
        for(int ii = 0; ii < 3; ii++) for(int jj = 0; jj < 3; jj++) 
          if(i&(1 << ii)) if(j &(1<<jj)) {
            if(abs(ii - jj) <= 1) no = 1;
          }
        if(no) continue;
        dp[y+1][j] = max(dp[y+1][j], dp[y][i] + cnt);
        ans = max(ans, dp[y + 1][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

C++: #include <iostream>
#define INF 1e+9
using namespace std;

int b(int a1,int a2,int a3,int a4){
	return a1 + a2 * 2 + a3 * 4 + a4 * 8;
}

int main(){
	int h,n,dp[10010][16] = {};
	int ng[10010][4] = {};
	cin >> h >> n;
	for(int i = 0;i < n;i++){
		int x,y;
		cin >> x >> y;
		ng[y][x] = 1;
	}
	int tmp = 0;
	for(int i = 0;i < 4;i++){
		if(ng[0][i]) tmp += (1 << i);
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < 16;j++) dp[i][j] = -INF;
	}
	dp[0][tmp] = 0;
	for(int i = 1;i < h;i++){
		for(int j = 0;j < 16;j++){
			bool a[4] = {};
			for(int k = 0;k < 4;k++){
				if(!((j >> k) & 1) && !ng[i][k]) a[k] = true;
			}
			dp[i][b(ng[i][0],ng[i][1],ng[i][2],ng[i][3])] = max(dp[i][b(ng[i][0],ng[i][1],ng[i][2],ng[i][3])],dp[i - 1][j]);
			if(a[0] && a[1]) dp[i][b(1,1,ng[i][2],ng[i][3])] = max(dp[i][b(1,1,ng[i][2],ng[i][3])],dp[i - 1][j] + 1);
			if(a[1] && a[2]) dp[i][b(ng[i][0],1,1,ng[i][3])] = max(dp[i][b(ng[i][0],1,1,ng[i][3])],dp[i - 1][j] + 1);
			if(a[2] && a[3]) dp[i][b(ng[i][0],ng[i][1],1,1)] = max(dp[i][b(ng[i][0],ng[i][1],1,1)],dp[i - 1][j] + 1);
			if(a[0] && a[1] && a[2] && a[3]) dp[i][15] = max(dp[i][15],dp[i - 1][j] + 2);
		}
	}
	int ma = 0;
	for(int i = 0;i < 16;i++) ma = max(ma,dp[h - 1][i]);
	cout << ma << endl;
	return 0;
}