Đề bài: http://vn.spoj.com/problems/PBCDEM/
Thuật toán:
- (đang cập nhập)
Code:
using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 5001;
const int INF = 1e9 + 7;
string f[5001][101];
int n;
string operator +(string a, string b)
{
FORE(i, a.length(), b.length() - 1) a = '0' + a;
FORE(i, b.length(), a.length() - 1) b = '0' + b;
string c = a;
int nho = 0;
FORD(i, a.length() - 1, 0){
int tmp = (a[i] - '0') + (b[i] - '0') + nho;
c[i] = (tmp % 10 + '0');
nho = tmp / 10;
}
if (nho) c = '1' + c;
return c;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
//cout<<"wtf"<<endl;
int cur = 0, prev = 1;
FORE(i, 0, n + 2) FORE(j, 0, 100) f[i][j] = '0';
f[0][0] = "1";
FORE(i, 1, n) FORE(j, 1, trunc(sqrt(i*2)) + 1) if (1LL * j * (j + 1) <= 2 * i) f[i][j] = f[i - j][j] + f[i - j][j - 1];
string ans = "0";
FORE(j, 2, trunc(sqrt(n*2)) + 1) ans = ans + f[n][j];
cout<<ans;
return 0;
} |
Speak Your Mind