HDU1134 Game of Connections 高精度+DP

Problem Address:http://acm.hdu.edu.cn/showproblem.php?pid=1134


【思路】


dp状态转移:dp[i] = sum(dp[j]*dp[i-1-j])  [0<=j

加上高精度乘法和加法。


【代码】

代码又颓了= =

看来得准备一个高精度的模板啊!


#include 
using namespace std;

const int maxn = 100;

const int size = 100;  

struct num  
{  
    int n[size];  
    int len;  
    num()  
    {  
        memset(n, 0, sizeof(n));  
        len = 1;  
    }  
}d[maxn+5];

void multiply(num &t, num s)
{  
    int i,j;  
    num a;  
    for (i=0; i=10)  
        {  
            a.n[i+1] += a.n[i]/10;  
            a.n[i] = a.n[i]%10;  
        }  
    }  
    for (i=size-1; i>=0; i--)  
    {  
        if (a.n[i]!=0) break;  
    } 
    a.len = i+1;
    if (a.len==0)  
        a.len = 1;
    for (i=0; i=10)  
        {  
            a.n[i+1] += a.n[i]/10;  
            a.n[i] = a.n[i]%10;  
        }  
    }  
    for (i=size-1; i>=0; i--)  
    {  
        if (a.n[i]!=0) break;  
    } 
    a.len = i+1;
    if (a.len==0)  
        a.len = 1;
    for (i=0; i=0; i--) printf("%d", a.n[i]);
	printf("\n");
}  

int main()
{
	int i, j;
	d[0].n[0] = 1;
	d[0].len = 1;
	d[1].n[0] = 1;
	d[1].len = 1;
	for (i=2; i<=maxn; i++)
	{
		num temp;
		for (j=0; j


你可能感兴趣的:(综合,动态规划,struct,output)