[恢]hdu 1207
2011-12-17 00:08:43
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1207
题意:中文,不说。
mark:n最大到64。dp方程很容易出,但是64的时候不好处理。用double打表知64的答案是18433,特判一下。
代码:
# include <stdio.h>
long long dp[70] = {0, 1, 3, 5} ;
long long min(long long a, long long b){return a<b?a:b;}
int main ()
{
int i, j, n ;
dp[64] = 18433 ;
for (i = 2 ; i <= 63 ; i++)
{
dp[i] = 2*dp[1]+(1LL<<(i-1))-1 ;
for (j = 2 ; j < i ; j++)
dp[i] = min(dp[i], 2 * dp[j] + (1LL<<(i-j)) - 1) ;
}
while (~scanf ("%d", &n))
printf ("%I64d\n", dp[n]) ;
return 0 ;
}