Codeforces Testing Round #14 (Unrated) - B - Door Frames(DFS)

B. Door Frames
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side.

Determine a minimal number of wooden bars which are needed to make the frames for two doors. Petya can cut the wooden bars into any parts, but each side of each door should be a solid piece of a wooden bar (or a whole wooden bar).

Input

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the length of each wooden bar.

The second line contains a single integer a (1 ≤ a ≤ n) — the length of the vertical (left and right) sides of a door frame.

The third line contains a single integer b (1 ≤ b ≤ n) — the length of the upper side of a door frame.

Output

Print the minimal number of wooden bars with length n which are needed to make the frames for two doors.

Examples
input
8
1
2
output
1
input
5
3
4
output
6
input
6
4
2
output
4
input
20
5
6
output
2
Note

In the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.

In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed.



题意:

有很多长度为n的木条,要用这些木条做两个完全相同的门框

门框的左右两边长度为a,上面的长度为b

求最少需要几条长度为n的木头才能做出两个完全相同的门框



刚开始没想请直接贪心写了交上去立马就被hank了,后来发现那样贪心不行尴尬

因为状态比较少,所以直接DFS遍历一下,找到最小的答案就行了



#include <iostream>
#include <string.h>
#include <stdio.h>
#define LL long long
using namespace std;
const int N = 1e3 + 10;
int T,n,m,x,y,z,ans = 10;
int len[10][10],vis[10][10][10];
void dfs(int aa,int bb,int use){
    if(vis[aa][bb][use]||use > 6) return;
    vis[aa][bb][use] = 1;
    if(aa + bb == 0){
        ans = min(ans, use);
        return;
    }
    for(int i=0;i<=aa;i++){
        for(int j=0;j<=bb;j++){
            if(x < len[i][j]) continue;
            dfs(aa-i,bb-j,use+1);
        }
    }
}
int main()
{
    scanf("%d%d%d",&x,&y,&z);
    for(int i=0;i<=4;i++){
        for(int j=0;j<=2;j++){
            len[i][j] = y * i + z * j;
        }
    }
    dfs(4,2,0);
    printf("%d\n",ans);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值