zoukankan      html  css  js  c++  java
  • POJ 3181 Dollar Dayz

    Description
    Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for 1, 2, and 3. Farmer John has exactly $5 to spend. He can buy 5 tools at 1 each or 1 tool at 3 and an additional 1 tool at 2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are:
    Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of 1..K (1 <= K <= 100).

    题目大意:求[1,k]的数构成N的方案数,每个数可以用无限次
    解题报告:有一种操作叫 入门+高精=提高,这题就是,无限背包板子题,只要加上一个高精度即可,但是这题数据不是很大,两个longlong18位一存即可

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #define RG register
    #define il inline
    #define iter iterator
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    using namespace std;
    typedef long long ll;
    ll f[1005],g[1005];
    void work()
    {
    	int n,k;
    	scanf("%d%d",&n,&k);
    	f[0]=1;
    	ll lim=1e18;
    	for(int i=1;i<=k;i++){
    		for(int j=i;j<=n;j++){
    			g[j]=g[j]+g[j-i]+(f[j]+f[j-i])/lim;
    			f[j]=(f[j]+f[j-i])%lim;
    		}
    	}
    	if(g[n]>0)printf("%lld",g[n]);
    	printf("%lld
    ",f[n]);
    }
    
    int main()
    {
    	work();
    	return 0;
    }
    
    
  • 相关阅读:
    Oracle 更改DBID
    Oracle 修改字段长度
    Oracle 索引
    Oracle在无法打开数据库的状态下获取DBID
    Oracle 备份脚本
    Linux crontab计划任务
    Oracle restore和recovery的区别
    Django基础
    面向对象(一)
    socket
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7499317.html
Copyright © 2011-2022 走看看