Description
给一长度为 n n 的木棒,要求将其切成若干长度为的木棒,且木棒数量尽可能多
Input
四个整数 n,a,b,c(1≤n,a,b,c≤4000) n , a , b , c ( 1 ≤ n , a , b , c ≤ 4000 )
Output
输出木棒数量最大值,保证有解
Sample Input
5 5 3 2
Sample Output
2
Solution
简单题,暴力枚举长度为 a,b a , b 的木棒数量判合法即可
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=4005;
int main()
{
int n,a,b,c;
while(~scanf("%d%d%d%d",&n,&a,&b,&c))
{
int ans=0;
for(int i=0;i*a<=n;i++)
for(int j=0;j*b<=n;j++)
if(i*a+j*b<=n&&(n-i*a-j*b)%c==0)
ans=max(ans,i+j+(n-i*a-j*b)/c);
printf("%d\n",ans);
}
return 0;
}