zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 044 C

    题目链接:http://abc044.contest.atcoder.jp/tasks/arc060_a

    Time limit : 2sec / Memory limit : 256MB

    Score : 300 points

    Problem Statement

    Tak has N cards. On the i-th (1≤iN) card is written an integer xi. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?

    Constraints

    • 1≤N≤50
    • 1≤A≤50
    • 1≤xi≤50
    • N, A, xi are integers.

    Partial Score

    • 200 points will be awarded for passing the test set satisfying 1≤N≤16.

    Input

    The input is given from Standard Input in the following format:

    N A
    x1 x2  xN
    

    Output

    Print the number of ways to select cards such that the average of the written integers is exactly A.


    Sample Input 1

    Copy
    4 8
    7 9 8 9
    

    Sample Output 1

    Copy
    5
    
    • The following are the 5 ways to select cards such that the average is 8:
      • Select the 3-rd card.
      • Select the 1-st and 2-nd cards.
      • Select the 1-st and 4-th cards.
      • Select the 1-st, 2-nd and 3-rd cards.
      • Select the 1-st, 3-rd and 4-th cards.

    Sample Input 2

    Copy
    3 8
    6 6 9
    

    Sample Output 2

    Copy
    0
    

    Sample Input 3

    Copy
    8 5
    3 6 2 8 7 6 5 9
    

    Sample Output 3

    Copy
    19
    

    Sample Input 4

    Copy
    33 3
    3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
    

    Sample Output 4

    Copy
    8589934591
    
    • The answer may not fit into a 32-bit integer

    题意:给定一串数字,问能够组成多少种不连续子串使得子串的平均数为某个数

    题解:用动态规划,i表示相加的个数,j表示加起来后的值

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 using namespace std;
    14 #define lowbit(x) (x&(-x))
    15 #define max(x,y) (x>y?x:y)
    16 #define min(x,y) (x<y?x:y)
    17 #define MAX 100000000000000000
    18 #define MOD 1000000007
    19 #define pi acos(-1.0)
    20 #define ei exp(1)
    21 #define PI 3.141592653589793238462
    22 #define INF 0x3f3f3f3f3f
    23 #define mem(a) (memset(a,0,sizeof(a)))
    24 typedef long long ll;
    25 ll gcd(ll a,ll b){
    26     return b?gcd(b,a%b):a;
    27 }
    28 bool cmp(int x,int y)
    29 {
    30     return x>y;
    31 }
    32 const int N=55;
    33 const int mod=1e9+7;
    34 ll dp[N][N*N];
    35 int main()
    36 {
    37     int n,a;
    38     cin>>n>>a;
    39     dp[0][0]=1;
    40     for(int i=1;i<=n;i++){
    41         int x;
    42         cin>>x;
    43         for(int j=i-1;j>=0;j--)
    44             for(int k=0;k<=N*j;k++)
    45                 dp[j+1][k+x]+=dp[j][k];
    46     }
    47     ll ans=0;
    48     for(int i=1;i<=n;i++)
    49         ans+=dp[i][i*a];
    50     cout<<ans<<endl;
    51     return 0;
    52 }
  • 相关阅读:
    NS3 使用NS3工具PyViz
    ns-3 NetAnim遇到了一个问题
    NS-3 MyFirstScriptExample
    Ubuntu下Eclipse安装与编译ns-3遇见的各种问题
    Ubuntu 12.04 安装JDK
    近期学习的参考博客链接
    Win7上安装WMware虚拟机和Ubuntu操作系统
    C++课程小结 继承与派生
    C语言中生产随机数 rand()函数
    PTA第三次上机
  • 原文地址:https://www.cnblogs.com/shixinzei/p/7289324.html
Copyright © 2011-2022 走看看