[恢]hdu 1865
生活随笔
收集整理的這篇文章主要介紹了
[恢]hdu 1865
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2011-12-24 20:04:44
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1865
題意:若干個(gè)1,可以選擇相鄰兩個(gè)合并成2。問(wèn)有多少種可能的結(jié)果。
mark:考慮最后一個(gè)數(shù)是1或2,可得遞推dp[i] = dp[i-1]+dp[i-2]。但是最大是200,大概是10^50,所以要用大數(shù)加法。
代碼:
# include <stdio.h># include <string.h>
int tab[210][50] = {{1, 1}, {1, 1}} ;
char str[210] ;
void add(int a[], int b[], int c[])
{
int i, *p, *q, cc = 0 ;
if (a[0] <= b[0]) p = a, q = b ;
else p = b, q = a ;
for (i = 1 ; i <= q[0] ; i++)
{
if (i <= p[0]) c[i] = p[i] ;
c[i] += cc + q[i] ;
cc = c[i] / 10 ;
c[i] %= 10 ;
}
if (cc != 0) c[i++] = cc ;
c[0] = i-1 ;
}
void output (int a[])
{
int i, len = a[0] ;
for (i = len ; i >= 1 ; i--)
printf ("%d", a[i]) ;
printf ("\n") ;
}
int main ()
{
int i, T, len ;
for (i = 2 ; i <= 200 ; i++)
add(tab[i-1], tab[i-2], tab[i]) ;
scanf ("%d", &T) ;
while (T--)
{
scanf ("%s", str) ;
len = strlen (str) ;
output (tab[len]) ;
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/lzsz1212/archive/2012/01/06/2315339.html
總結(jié)
以上是生活随笔為你收集整理的[恢]hdu 1865的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 年终,我们有了收获
- 下一篇: luatex plain 从零构建