题目链接: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表示加起来后的值

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
ll dp[N][N*N];
int main()
{
int n,a;
cin>>n>>a;
dp[][]=;
for(int i=;i<=n;i++){
int x;
cin>>x;
for(int j=i-;j>=;j--)
for(int k=;k<=N*j;k++)
dp[j+][k+x]+=dp[j][k];
}
ll ans=;
for(int i=;i<=n;i++)
ans+=dp[i][i*a];
cout<<ans<<endl;
return ;
}

AtCoder Beginner Contest 044 C - 高橋君とカード / Tak and Cards的更多相关文章

  1. AtCoder Beginner Contest 044 A - 高橋君とホテルイージー / Tak and Hotels (ABC Edit)

    Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There is a hotel with ...

  2. 高橋君とカード / Tak and Cards

    高橋君とカード / Tak and Cards Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB Score : 300 p ...

  3. 高橋君とカード / Tak and Cards AtCoder - 2037 (DP)

    Problem Statement Tak has N cards. On the i-th (1≤i≤N) card is written an integer xi. He is selectin ...

  4. 高橋君とホテル / Tak and Hotels

    高橋君とホテル / Tak and Hotels Time limit : 3sec / Stack limit : 256MB / Memory limit : 256MB Score : 700  ...

  5. AtCoder Beginner Contest 044 B - 美しい文字列 / Beautiful Strings

    Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Let w be a string cons ...

  6. AtCoder Beginner Contest 022 A.Best Body 水题

    Best Body Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://abc022.contest.atcoder.jp/tasks/abc02 ...

  7. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  8. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

  9. AT987 高橋君

    AT987 高橋君 给出 \(n,\ k\) ,求 \(\displaystyle\sum_{i=0}^kC_n^k\) , \(T\) 次询问 \(T\leq10^5,\ 0\leq k\leq n ...

随机推荐

  1. laravel出现No hint path defined for [sudosu]的解决方法

    今天ytkah在部署laravel项目时出现了No hint path defined for [sudosu]的问题,大概意思是没有定义sudosu的提示路径,那我们找一下配置文件有没相关设置,看到 ...

  2. 容器化 RDS:你须要了解数据是怎样被写&quot;坏&quot;的

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/M2l0ZgSsVc7r69eFdTj/article/details/79877076 容器化 RD ...

  3. MySQL表操作及数据操作

    表操作 表相当于一个文件,其形式与现实中的表格相同.表中的每条记录都有相应的字段,字段就类似于表格的表头. 表操作详细: #对表进行操作(文件) #首先要切换到指定库(即文件夹)下:use db1; ...

  4. chrome版本与对应的谷歌驱动(chromedriver)

    chrome版本与对应的谷歌驱动(chromedriver) 1.下载chromedriver:http://chromedriver.storage.googleapis.com/index.htm ...

  5. 008-Centos 7.x安装 Ambari 2.2.2 + HDP 2.4.2 搭建Hadoop集群

    1.安装环境说明 安装前先安装好 Centos 7.2, jdk-8u91, mysql5.7.13 一共有3台机器,一个是主节点192.168.111.10,两个是从:192.168.111.11, ...

  6. testrem

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  7. 静态库lib和动态库dll相关总结

    1.静态链接库LIB和动态链接库DLL的区别 若采用静态链接库,lib 中的指令都全部被直接包含在最终生成的 EXE 文件中了.而动态动态链接库则不必被包含在最终 EXE 文件中,EXE 文件执行时可 ...

  8. [django]模板中自定义变量&django模板中的变量

    django自定义模板变量 context_processors.py def mysetings(request): return { 'NAME': 'maotai' } settings.py ...

  9. 继承时,当父子类都具有相同的成员变量,默认情况下是直接调用子类的成员变量,当要调用父类的成员变量则需要使用super关键之

    package day02; public class Person { String name="fl"; }class Car{ }class Student extends ...

  10. solr创建业务域以及指定中文分析器IK

    第一步:把中文分析器添加到工程中. 1.把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下 2.把扩展词典.配置文件放到solr工程的WEB-INF/classes目录下 ...