zoukankan      html  css  js  c++  java
  • 取模

    源代码:
    
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int n,x,i[21];
    bool Flag,Vis[21]={0};
    bool Rule(int t1,int t2)
    {
        return t1>t2;
    }
    void DFS(int T,int L,int S,int Limit) //利用mod性质,进行区间剪枝。
    {
        if (!T)
        {
            Flag=true;
            return;
        }
        if (S==Limit)
          return;
        for (int a=L;a<=n;a++)
          if (!Vis[a])
          {
              Vis[a]=true;
              DFS(T%i[a],a+1,S+1,Limit);
              Vis[a]=false;
              if (Flag)
                return;
          }
    }
    void Solve()
    {
        Flag=false;
        sort(i+1,i+n+1,Rule);
        for (int a=1;a<=n;a++) //迭代深搜。
          for (int b=1;b<=n;b++)
          {
            Vis[b]=true;
            DFS(x%i[b],b+1,1,a);
            Vis[b]=false;
            if (Flag)
            {
                printf("%d
    ",a);
                return;
            }
          }
        printf("-1
    ");
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            scanf("%d%d",&n,&x);
            for (int a=1;a<=n;a++)
              scanf("%d",&i[a]);
            Solve();
        }
        return 0;
    }
  • 相关阅读:
    【转】 Linux进程间通信
    Django中的Templates
    Django中的应用
    url的使用
    Django框架的使用
    Django的安装
    文件上传
    flask中的request和response
    模板
    静态文件处理
  • 原文地址:https://www.cnblogs.com/Ackermann/p/6024550.html
Copyright © 2011-2022 走看看