高橋君とカード / Tak and Cards


Time limit : 2sec / Stack limit : 256MB / 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

4 8
7 9 8 9

Sample Output 1

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.

分析:二维背包;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000000
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
ll dp[][];
int a,now;
ll ans;
int main()
{
int i,j;
dp[][]=;
scanf("%d%d",&n,&a);
rep(i,,n)
{
scanf("%d",&k);
now+=k;
for(j=i;j>=;j--)
for(t=now;t>=k;t--)
dp[j][t]+=dp[j-][t-k];
}
rep(i,,n)ans+=dp[i][a*i];
printf("%lld\n",ans);
//system("Pause");
return ;
}

高橋君とカード / Tak and Cards的更多相关文章

  1. 高橋君とカード / 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 ...

  2. AtCoder Beginner Contest 044 C - 高橋君とカード / Tak and Cards

    题目链接:http://abc044.contest.atcoder.jp/tasks/arc060_a Time limit : 2sec / Memory limit : 256MB Score ...

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

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

  4. 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 ...

  5. AT987 高橋君

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

  6. 【AT987】高橋君

    题目 成爷爷一眼秒,\(tql!!!\) 多组询问,求 \[\sum_{i=0}^kC_{n}^i \] 发现\(k<=n\)啊,于是我们可以把一组询问抽象成一个区间\([k,n]\) 左指针的 ...

  7. AtCoder D - 高橋君と見えざる手 / An Invisible Hand 简单思维题

    http://arc063.contest.atcoder.jp/tasks/arc063_b 因为每次都是选取最大值,那么用dp[i]表示第i个数结尾能得到最大是多少. 其实就是用a[i]去减去左边 ...

  8. 2018.09.17 atcoder Tak and Cards(背包)

    传送门 背包经典题. 直接f[i][j]f[i][j]f[i][j]表示选i张牌和为j的方案数. 最后统计答案就行了. 代码: #include<bits/stdc++.h> #defin ...

  9. AtCoder-arc060 (题解)

    A - 高橋君とカード / Tak and Cards (DP) 题目链接 题目大意: 有 \(n\) 个数字,要求取出一些数字,使得它们的平均数恰好为 \(x\) ,问有几种取法. 大致思路: 只要 ...

随机推荐

  1. ios控件 UILabel

    UILabel 的作用是显示文本 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 40)]; lab ...

  2. liunx 内存文件 tmpfs

    tmpfs是Linux/Unix系统上的一种基于内存的文件系统.tmpfs可以使用您的内存或swap分区来存储文件 1 创建将被挂载的文件 mkdir /tmp/tmpfs/ 2 写入测试文件内容.大 ...

  3. linux 配置tomcat服务器

    1. 找到tomcat安装包    find / -name apache-tomcat* 2. 解压包 tar zxvf apache-tomcat-7.0.67.tar.gz rpm -ivh j ...

  4. Linux KVM 安装配置

    --------------------------一.前言二.环境三.安装与配置四.创建kvm虚拟机 一.前言 KVM,即Kernel-based Virtual Machine的简称,是一个开源的 ...

  5. linq中first() firstordefault() last() lastOrDefault() single() singleOrDeafult

    一.firstordefault() 和 first() class Program { static void Main(string[] args) { List<Emp> list ...

  6. asp.net如何删除文件夹及文件内容操作

    static void DeleteDirectory(string dir) { && Directory.GetFiles(dir).Length == ) { Directory ...

  7. sql server 的datediff函数

    这两天要把一个sqlserver数据库的程序改成oracle的,发现两个数据库之间的函数很多不一样.sqlserver的数据库中的DateDiff 函数用法解释如下: 描述 返回两个日期之间的时间间隔 ...

  8. UIImageView 浅析

    UIImageView summary UIImageView极其常用,功能比较专一:显示图片 pooperty @property(nonatomic,retain) UIImage *image; ...

  9. JS-DOM操作应用

    父级.appendChild(子节点) 父级.insertBefore(子节点,在谁之前) <title>无标题文档</title> <script> window ...

  10. PAT (天梯)L2-004. 这是二叉搜索树吗?

    L2-004. 这是二叉搜索树吗? 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一棵二叉搜索树可被递归地定义为具有下列性质的 ...