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

    向php脚本中传参数可以用http GET 方法,比如要向file.php传两个参数v1和v2.则可以这么做 file.php?v1=&v2= (一个链接而已,直接编辑URL即可传参数了) 这 ...

  2. 避免IE执行AJAX时,返回JSON出现下载文件

    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.conv ...

  3. makesfx.exe (Make SFX (Self-extracting archive))

    来源: http://www.cr173.com/soft/5500.html http://74.cz/en/make-sfx/ 官方,最新 Make SFX 是一套Win32平台下能让您制作自解压 ...

  4. mongodb启动

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可护展的高性能数据存储解决方案.MongoDB是一款分布式文档数据库,支持类似关型数据库的主从结构,文档以二进制J ...

  5. iwlist等工具的移植

    http://blog.csdn.net/jk110333/article/details/8658054 参考了这边文章 -------------------------------------- ...

  6. Ztree当节点没有下级时不显示下拉图标

    select o.*,(select count(*) from sys_org t where t.orgsupid=o.orgid) isLeaf from sys_org o where 1=1

  7. jave学习1--基础介绍

    java 技术主要分为三个部分: jave SE基础知识. 对于各个程序的开发语言都包含的基本数据类型,循环控制,数组,方法等. jave SE的面向对象部分. 所有的面向对象的概念,为最终的接口准备 ...

  8. Rar related CMD

    recursively add folder Document to archive: (with all the files) rar a *.rar Document recursively ad ...

  9. [转]用android LinearLayout和RelativeLayout实现精确布局

    先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...

  10. java 网络编程Socket编程

    Server.java import java.io.*; import java.net.*; public class Server { public static void main(Strin ...