简答题
偏难
#7335
铺砖(2023.3) 对于一个2行N列的走道。现在用1*2,2*2的砖去铺满。问有多少种不同的方式。 时间限制:3000 内存限制:131072 输入 整个测试…
铺砖(2023.3)
对于一个2行N列的走道。现在用1*2,2*2的砖去铺满。问有多少种不同的方式。
时间限制:3000
内存限制:131072
输入
整个测试有多组数据,请做到文件底结束。每行给出一个数字N,0 <= n <= 250
输出
如题
样例输入
2 8 12 100 200
样例输出
3 171 2731 845100400152152934331135470251 1071292029505993517027974728227441735014801995855195223534251
答案与解析
正确答案:<pre class="brush:cpp;toolbar:false">#include <algorithm>
#include <iostream>
using namespace std;
string myadd(string a, string b) {
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int len;
if (a.length() > b.length()) {
len = a.length();
while (b.length() == len)
b += " ";
} else {
len = b.length();
while (a.length() == len)
a += " ";
}
int i = 0, t = 0;
string ans;
while (i < len) {
t += a[i] + b[i] - '0' - '0';
ans += (t % 10 + '0');
t /= 10;
i++;
}
if (t > 0)
ans += t + '0';
reverse(ans.begin(), ans.end());
return ans;
}
int main() {
int n;
string dp[300];
dp[0] = "1";
dp[1] = "1";
dp[2] = "3";
for (int i = 3; i <= 250; i++) {
dp[i] = myadd(dp[i - 1], myadd(dp[i - 2], dp[i - 2]));
}
while (cin >> n) {
cout << dp[n] << endl;
}
return 0;
}</pre>
这道题暂未补解析。