当前位置: 代码迷 >> 综合 >> HDU 1502 Regular Words 打表+大数相加 .
  详细解决方案

HDU 1502 Regular Words 打表+大数相加 .

热度:94   发布时间:2023-09-23 06:18:37.0

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1502

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=60+5;
typedef long long LL;
struct BigInteger{static const int BASE=100000000;static const int WIDTH=8;vector<int> s;BigInteger(LL num=0) { *this = num ; }BigInteger operator = (LL num){s.clear();do{s.push_back(num%BASE);num /= BASE;}while(num>0);return *this;}BigInteger operator = (const string& str){s.clear();int x,len=(str.length()-1) / WIDTH + 1;for(int i=0;i<len;i++){int end=str.length()-i*WIDTH;int start=max(0,end-WIDTH);sscanf(str.substr(start,end-start).c_str(),"%d",&x);s.push_back(x);}return *this;}BigInteger operator + (const BigInteger& b) const {BigInteger c;c.s.clear();for(int i=0,g=0;;i++){if(g==0&&i>=(int)s.size()&&i>=(int)b.s.size()) break;int x=g;if(i<(int)s.size()) x+=s[i];if(i<(int)b.s.size()) x+=b.s[i];c.s.push_back(x%BASE);g=x/BASE;}return c;}BigInteger operator += (const BigInteger& b){*this = *this + b;return *this;}
};
ostream& operator << (ostream &out,const BigInteger& x){out<<x.s.back();for(int i=x.s.size()-2;i>=0;i--){char buf[20];sprintf(buf,"%08d",x.s[i]);for(int j=0;j<(int)strlen(buf);j++) out<<buf[j];}return out;
}
BigInteger d[maxn][maxn][maxn];
int main(int argc, char const *argv[])
{int n;d[1][0][0]=1;for(int a=1;a<=60;a++)for(int b=0;b<=a;b++)for(int c=0;c<=b;c++){if(a>0) d[a][b][c]+=d[a-1][b][c];if(b>0) d[a][b][c]+=d[a][b-1][c];if(c>0) d[a][b][c]+=d[a][b][c-1];}while(cin>>n)cout<<d[n][n][n]<<endl<<endl;return 0;
}