P1616 疯狂的采药
查看原帖
P1616 疯狂的采药
525998
huangjiasheng楼主2022/2/5 09:56

P1616 疯狂的采药

我的代码不知道有什么问题 90分

想向各位大佬求助!!!

/*****************************************
备注:
******************************************/
#include <queue>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <iomanip>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 3e7 + 10;
const int INF = 0x3f3f3f3f;
inline long long read()
{
    register long long x=0,f=0;
    register char t=getchar();
    while(t<'0'||t>'9')f^=(t=='-'),t=getchar();
    while(t>='0'&&t<='9')x=(x<<3)+(x<<1)+(t^48),t=getchar();
    return f?-x:x;
}
LL n,m,dp[N],a[N],b[N]; 
int main()
{
	n=read();
	m=read();
	for(int i=1;i<=m;i++)
	{
		a[i]=read();
		b[i]=read();
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=a[i];j<=n;j++)
		{
			dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
		}
	}
	printf("%d",dp[n]);
	return 0;
}
2022/2/5 09:56
加载中...