Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Last active June 12, 2019 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/9551b310c588f495c9f9532867e79a56 to your computer and use it in GitHub Desktop.
Save fpdjsns/9551b310c588f495c9f9532867e79a56 to your computer and use it in GitHub Desktop.
[algospot][DP] 비대칭 타일링 : https://algospot.com/judge/problem/read/ASYMTILING
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
/*
* 시간복잡도 : O(N)
*/
using namespace std;
int MOD = 1000000007;
vector<int> dp;
int getAll(int n) {
if (n <= 1) return dp[n] = 1;
int& ret = dp[n];
if (ret != -1) return ret;
ret = (getAll(n - 1) + getAll(n - 2)) % MOD;
return ret;
}
int getSymmetry(int n) {
int ans = dp[n / 2];
if (n % 2 == 0)
ans = (ans + dp[n / 2 - 1]) % MOD;
return ans;
}
int main() {
int C;
cin >> C;
dp = vector<int>(101, -1);
while (C--) {
int N;
cin >> N;
int answer = (getAll(N) + MOD - getSymmetry(N)) % MOD;
cout << answer << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment