zoukankan      html  css  js  c++  java
  • 计蒜客 方程的解数(DFS)

    问题描述

    输出格式

    输出一行,输出一个整数,表示方程的整数解的个数。

    样例输入

    3
    100
    1 2
    -1 2
    1 2

    样例输出

    104
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 const double PI = acos(-1);
    17 const double eps =1e-8;
    18 #define Bug cout<<"---------------------"<<endl
    19 const int maxn=1e5+10;
    20 using namespace std;
    21 
    22 int k[5],p[5]; 
    23 int n,m,ans;
    24 LL POW[150][5];//POW[i][j]表示i的j次方 
    25 
    26 void init()//打表
    27 {
    28     for(int i=1;i<=150;i++)
    29     {
    30         POW[i][0]=1;
    31         for(int j=1;j<=4;j++)
    32         {
    33             POW[i][j]=i*POW[i][j-1];
    34         }
    35     }
    36 }
    37 
    38 void DFS(int step,LL sum)
    39 {
    40     if(step>n)
    41     {
    42         if(sum==0) ans++;
    43         return ;
    44     }
    45     for(int i=1;i<=m;i++)
    46         DFS(step+1,sum+k[step]*POW[i][p[step]]);
    47 }
    48 
    49 int main()
    50 {
    51     #ifdef DEBUG
    52     freopen("sample.txt","r",stdin);
    53     #endif
    54     ios_base::sync_with_stdio(false);
    55     cin.tie(NULL);
    56     
    57     scanf("%d %d",&n,&m);
    58     for(int i=1;i<=n;i++)
    59         scanf("%d %d",&k[i],&p[i]);
    60     init();//不要忘了 
    61     DFS(1,0);
    62     printf("%d
    ",ans);
    63     
    64     return 0;
    65 }

    -

  • 相关阅读:
    Lombok 安装、入门
    详细解析@Resource和@Autowired的区别 , 以及@Qualifier的作用
    Spring中@Resource与@Autowired、@Qualifier的用法与区别
    springMVC整合swagger
    jetty maven插件
    【原创】Sagger使用
    Eclipse详细设置护眼背景色和字体颜色
    eclipse中相同代码的高亮显示
    Mybatis分页插件
    mybatis
  • 原文地址:https://www.cnblogs.com/jiamian/p/12174333.html
Copyright © 2011-2022 走看看