题目链接: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. Python3学习之路~6.7 经典类和新式类的继承顺序

    在Python中,经典类(class Person:)和新式类(class Person(object):)的主要区别就是体现在多继承的顺序上. Python 2.x中默认都是经典类,只有显式继承了o ...

  2. 004-读书笔记-企业IT架构转型之道-阿里巴巴中台战略思想与架构实战-共享服务中心建设原则

    一般来说服务能力包括两个层次,一个是底层paas的能力,PaaS层结局大型架构在分布式.可靠性.可用性.容错.监控以及运维层面上的通用需求:第二个层次是业务能力,业务能力提供云化的核心业务支撑能力,这 ...

  3. 最少步数(bfs)

    最少步数 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 这有一个迷宫,有0~8行和0~8列: 1,1,1,1,1,1,1,1,1 1,0,0,1,0,0,1,0,1 ...

  4. 云服务器--linux系统操作命令以及安装ngnix记录,以及手动部署本地文件

    1.控制台登陆服务器,需要首先知道服务器ip和密码,,命令是 ssh root@1.1.1.1(服务器IP),然后输入密码登入服务器 2.查看linux 版本的系统命令是 cat /etc/redha ...

  5. HTTP协议和WEB框架

    一.HTTP协议 <<HTTP权威指南>>读书笔记:https://www.cnblogs.com/qcssmd/p/5508150.html 一.HTTP简介 HTTP协议是 ...

  6. CentOS里alias命令

    alias命令 功能描述:我们在进行系统的管理工作一定会有一些我们经常固定使用,但又很长的命令.那我们可以给这些这一长串的命令起一个别名.之后还需要这一长串命令时就可以直接以别名来替代了.系统中已经有 ...

  7. Python爬虫常用模块安装

    安装:pip3 install requestspip3 install seleniumpip3 install bs4pip3 install pyquerypip3 install pymysq ...

  8. Python 全栈开发四 python基础 函数

    一.函数的基本语法和特性 函数的定义 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的.函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数 ...

  9. jenkins 新增用户和修改用户名密码

    在某些条件下,jenkins是不允许注册用户的,这是,你可以采用如下的方式来新增用户,对于老的用户,忘记密码了,使用如下方式来重置密码. 1.系统管理-->管理用户 ----> 新建用户 ...

  10. 一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(六)RTP音视频传输解析层之音视频数据传输格式

    一.差异 本地音视频数据格式和用来传输的音视频数据格式存在些许差异,由于音视频数据流到达客户端时,需要考虑数据流的数据边界.分包.组包顺序等问题,所以传输中的音视频数据往往会多一些字节. 举个例子,有 ...