Dollar Days POJ 3181 完全背包+高精度
2017-05-10 09:40
369 查看
这个和之前的Sumsets差不多,都是完全背包的模板题
但是这个我们要注意的是数的范围比较大,已经超了long long 了,我们需要用到高精度
参考http://www.cnblogs.com/kuangbin/archive/2012/09/20/2695165.html
模拟高精度加法
或者用两个long long 来实现
这里的a表示高位,b表示低位,当a不为0,b又没有到18位的时候记得要补0
但是这个我们要注意的是数的范围比较大,已经超了long long 了,我们需要用到高精度
参考http://www.cnblogs.com/kuangbin/archive/2012/09/20/2695165.html
模拟高精度加法
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1005; long long dp[maxn][100]; void ADD(int n,int m) { for(int i=0;i<=60;i++) { dp [i]+=dp[m][i]; if(dp [i]>=10) { dp [i]=dp [i]%10; dp [i+1]++; } } } int main() { int n,k; scanf("%d %d",&n,&k); dp[0][0]=1; for(int i=1;i<=k;i++) { dp[0][0]=1; for(int j=i;j<=n;j++) ADD(j,j-i); } int t=60; while(t>0&&dp [t]==0) t--; for(int i=t;i>=0;i--) printf("%d",dp [i]); printf("\n"); return 0; }
或者用两个long long 来实现
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn 4000 = 1005; long long a[maxn]; long long b[maxn]; const long long inf=1e18; int main() { int n,k; scanf("%d %d",&n,&k); b[0]=1; for(int i=1;i<=k;i++) { for(int j=i;j<=n;j++) { a[j]=a[j]+a[j-i]+(b[j]+b[j-i])/inf; b[j]=(b[j]+b[j-i])%inf; } } if(a ==0) printf("%I64d\n",b ); else printf("%I64d%018I64d\n",a ,b ); return 0; }
这里的a表示高位,b表示低位,当a不为0,b又没有到18位的时候记得要补0
相关文章推荐
- Dollar Days POJ 3181 完全背包+高精度
- Dollar Days POJ 3181 完全背包+高精度
- Dollar Days POJ 3181 完全背包+高精度
- Dollar Days POJ 3181 完全背包+高精度
- Dollar Days POJ 3181 完全背包+高精度
- Dollar Days POJ 3181 完全背包+高精度
- Dollar Days POJ 3181 完全背包+高精度
- POJ 3181 Dollar Dayz 完全背包 + 高精度
- POJ 3181 - Dollar Dayz(完全背包+高精度)
- Dollar Dayz POJ - 3181 dp,完全背包,简单高精度加法
- poj 3181 Dollar Dayz 高精度+完全背包
- POJ 3181 Dollar Dayz(完全背包+简单高精度加法)
- poj Dollar Dayz 3181 (DP&完全背包) 好题
- poj 3181 Dollar Dayz (完全背包+高精度)
- POJ--3181--Dollar Dayz--背包/高精度
- poj 3181 Dollar Dayz 钱币兑换问题 大数/高精度 完全背包
- POJ_3181_Dollar_Dayz_(动态规划,完全部分和,完全背包)
- poj 3181 完全背包计数+高精度
- poj 3181 Dollar Dayz dp 完全背包
- POJ 3181Dollar Dayz (完全背包求方法数,高精度dp)