2056: Jojer's Story IV

2056: Jojer's Story IV


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s16384K611121Standard
As you know, Mr. Jojer is very good at mathematics. Even when he got to Las Vegas, after several days he found he could win exactly 100 dollars each day with 21 points and 40 dollars with horse race, but he was tired of it then, so he wanted to win enough money to buy a ticket to come back. Is it easy? But now he just wants to win the exactly money with the least days, can he?

Input

Each test case will first give you two integers n(<500) the number of the games and m(<2000000) the money he wants to get exactly and follow by n integers to tell you the money he can win a special game each day.

Output

You should just output the minimum days or impossible.

Sample Input

2 250
100
50

Sample Output

3

 

Problem Source: fennec

 


This problem is used for contest: 11 

 

 

#include<iostream>
#include<algorithm>
using namespace std;
const int inf=(1<<31)-199;
int  n,goal,minc;
bool flag;
int a[600];
bool cmp(int x,int y)
{
    return x>y;
}
void dfs(int money,int count ,int mark)
{
    if(mark==n)  {if(money==0&&count<minc) {minc=count;flag=true;} return ;}
    if(count+ money/a[mark] >minc) return ;
    if(money<a[mark]) dfs(money,count,mark+1);
    int t=money/a[mark];
    int i;
    for(i=t;i>=0;i--)
    {
        dfs(money-a[mark]*i,count+i,mark+1);
    }
}
int main()
{
    int i,j;
    while(scanf("%d%d",&n,&goal)==2)
    {
        for(i=0;i<n;i++) scanf("%d",&a[i]);
        sort(a,a+n,cmp);
        flag=false;
        minc=inf;
        dfs(goal,0,0);
        if(flag) printf("%d/n",minc);
        else printf("impossible/n");
    }
    return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值