poj-2063-完全背包
来源:互联网 发布:ubuntu 重置网络设置 编辑:程序博客网 时间:2024/06/01 09:32
完全背包的一道题目。
注意:
1,因为每一个花费的为1000的整数倍,所以说可以把每一次的花费缩小为c[i]/1000;
2,注意使用memset函数是比较耗时间的,不能大量使用,最后手动初始化。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<stdlib.h>
#define INT_MAX 0x7fffffff
#define INF 999999
#define max3(a,b,c) (max(a,b)>c?max(a,b):c)
#define min3(a,b,c) (min(a,b)<c?min(a,b):c)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
struct node
{
int u;
int v;
int w;
bool friend operator < (node a, node b){
return a.w < b.w;
}
}edge[1001];
int gcd(int n,int m){if(n<m) swap(n,m);return n%m==0?m:gcd(m,n%m);}
int lcm(int n,int m){if(n<m) swap(n,m);return n/gcd(n,m)*m;}
int st;
int dp[1000001];
void packall(int cost,int weight)
{
int i;
for(i=cost;i<=st/1000;i++)
{
dp[i]=max(dp[i],dp[i-cost]+weight);
}
}
int main()
{
int T,i;
int year;
int n,c[11];
int w[11];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&st,&year);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&c[i],&w[i]);
c[i]=c[i]/1000;
}
while(year--)
{
for(i=0;i<=st/1000;i++)dp[i]=0;
for(i=1;i<=n;i++)
packall(c[i],w[i]);
st=st+dp[st/1000];
}
printf("%d\n",st);
}
return 0;
}
- POJ 2063 完全背包
- poj 2063 完全背包
- poj-2063-完全背包
- poj 2063完全背包
- POJ-2063 完全背包
- POJ 2063【完全背包】
- poj 2063 完全背包
- poj 2063 完全背包
- poj 2063 Investment 完全背包
- Poj 2063 Investment (完全背包)
- poj 2063 投资 完全背包
- POJ 2063 Investment 完全背包
- poj 2063 Investment 完全背包
- poj 2063 Investment (完全背包)
- poj 2063 多次完全背包
- POJ 2063 Investment 完全背包
- POJ 2063 Investment 完全背包
- POJ 2063 Investment (完全背包)
- 页面回收---LRU链表
- iOS NSTimer 定时器的使用
- MFC添加右键菜单
- 第八周上机任务项目1-1用类的成员函数完成运算符重载
- spring 概念描述
- poj-2063-完全背包
- Django CSRF设置方法
- Hibernate缓存相关(二)
- 博客的创建
- 第八周上机任务项目1-2用类的友元函数完成运算符的重载
- Anykey系列无线网桥
- 【QT】收集Q_OBJECT 是怎样的
- linux 文件操作的一些命令
- [Android] 将Android工程做成jar包和资源文件