A.Cut Ribbon
切断带
time limit per test: 1 second
每次测试的时间限制:1秒
memory limit per test:256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
Polycarpus has a ribbon, its length is n.He wants to cut the ribbon in a way that fulils the following two conditions:
Polycarpus has a ribbon, its length is n.He wants to cut the ribbon in a way that fulils the following two conditions:
. After the cutting each ribbon piece should have length a,b or c.
。剪裁后,每条丝带的长度应为a、b或c。
. After the cutting the number of ribbon pieces should be maximum.
。剪裁后,丝带的数量应该是最大的。
Help Polycarpus and find the number of ribbon pieces after the required cutting.
帮助Polycarpus找到剪裁后丝带的数量。
lnput
输入
The first line contains four space-separated integers n,a, b and c (1≤n,a,b,c≤4000)—the length of the original ribon and the
第一行包含四个空格分隔的整数n,a,b和c(1≤n,a,b,c≤4000)–原始Ribon的长度和
acceptable lengths of the ribbon pieces after the cutting, correspondingly.The numbers a, b and c can coincide.
剪裁后丝带的可接受长度相应。数a、b和c可重合。
output
输出量
Print a single number—the maximum possible number of rbon pieces.t is guaranteed that at least one correctribon cutting exists.
打印一个数字-最大可能数量的碳片。t是保证至少有一个正确的三边切割存在。
贪心
int main()
{
int n, a, b, c;
int i, j, t, max = 0;
cin >> n >> a >> b >> c;
for (i = 0; i <= n; i+=a)
{
for (j = 0; i + j <= n; j+=b)
{
if ((n - i - j ) % c == 0 && (n - i - j ) / c + i/a + j/b > max)
{
max = (n - i - j ) / c + i/a + j/b;
}
}
}
cout<< max << endl;
return 0;
}