Poj 2506 tiling High Precision

Source: Internet
Author: User

Question: Give A 2 * n bar area and ask how many ways to place a square with 2*1 and 2*2.


Train of Thought: F [I] = f [I-1] + F [I-2] * 2

Write a high-precision addition.


Code:

#include <cstdio>#include <cstring>#include <iomanip>#include <iostream>#include <algorithm>#define MAX 260#define BASE 1000using namespace std;struct BigInt{int num[MAX],len;BigInt(int _ = 0) {memset(num,0,sizeof(num));if(_) {num[1] = _;len = 1;}elselen = 0;}BigInt operator +(const BigInt &a)const {BigInt re;re.len = max(len,a.len);int temp = 0;for(int i = 1; i <= re.len; ++i) {re.num[i] = num[i] + a.num[i] + temp;temp = re.num[i] / BASE;re.num[i] %= BASE;}if(temp)re.num[++re.len] = temp;return re;}}f[MAX];ostream &operator <<(ostream &os,const BigInt &a) {os << a.num[a.len];for(int i = a.len - 1; i; --i)os << fixed << setfill('0') << setw(3) << a.num[i];return os;}int main(){f[0] = BigInt(1);f[1] = BigInt(1);f[2] = BigInt(3);for(int i = 3; i <= 250; ++i)f[i] = f[i - 1] + f[i - 2] + f[i - 2];int x;while(scanf("%d",&x) != EOF)cout << f[x] << endl;return 0;}


Poj 2506 tiling High Precision

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.