Problem Description

Tak has N cards. On the i-th (1≤i≤N) 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.

Example

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.

Sample Input 2

3 8
6 6 9

Sample Output 2

0

Sample Input 3

8 5
3 6 2 8 7 6 5 9

Sample Output 3

19

Sample Input 4

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

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

题意:有 n 张牌,每张牌有一个整数 xi,现在要在 n 张牌里选 1 或多张,使得所选的牌的平均值是 A,问有多少种选择方式

思路:

由于所给的数据范围不大,因此可设 dp[i][j] 为前 i 张卡上的数相加为 j 的方案数

那么首先枚举 n 件物品,每次考虑使得取得的卡数 i 减少 1 张,那么相应的和的最大值有 j+x[k],因此,对于前 i+1 张卡其相加的值为 j+x[k],那么组成的方案数 dp[i+1][j+x[k]] 就为原本的方案数再加上前 i 张卡的值,即:dp[i+1][j+x[k]]+=dp[i][j]

最后统计方案数即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 50+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int x[N];
LL dp[N][N*N];//dp[i][j]表示前i个数相加值为j的方案数
int main(){int n,a;scanf("%d%d",&n,&a);for(int i=1;i<=n;i++)scanf("%d",&x[i]);dp[0][0]=1;for(int k=1;k<=n;k++){//n个物品for(int i=k-1;i>=0;i--){//每次取得的物品个数减少for(int j=0;j<=50*i;j++){//统计相加的值,最大为50*idp[i+1][j+x[k]]+=dp[i][j];}}}LL res=0;for(int i=1;i<=n;i++){int val=i*a;//选择i个物品时他们平均值的总和res+=dp[i][val];}printf("%lld\n",res);return 0;
}

高橋君とカード / Tak and Cards(AtCoder-2037)相关推荐

  1. 高橋君とホテル / Tak and Hotels(AtCoder-2039)

    Problem Description N hotels are located on a straight line. The coordinate of the i-th hotel (1≤i≤N ...

  2. 【AT987】高橋君【组合数】【莫队】

    传送门 题意:TTT组询问NNN个相同物品选不超过KKK个的方案数,T,N≤1e5T,N \leq 1e5T,N≤1e5 设f(x,y)=∑i=0yCxif(x,y)=\sum_{i=0}^{y}C_ ...

  3. 明治维新VS洋务运动-同途殊归的变革by高铭君儿

    明治维新VS洋务运动-同途殊归的变革by高铭君儿 故事简介 我的产出 故事简介 朋友,您了解日本19世纪中叶的明治维新吗?您是否还记得同样是19世纪中叶发生,在中国的洋务运动呢?那些在高中课本里面的知 ...

  4. Tak and Cards(dp 背包)

    Tak and Cards 时间限制: 1 Sec  内存限制: 128 MB 题目描述 Tak has N cards. On the i-th (1≤i≤N) card is written an ...

  5. Tak and Cards(DP,二维背包)

    问题 K: Tak and Cards 时间限制: 1 Sec   内存限制: 128 MB 提交: 107   解决: 34 [ 提交][ 状态][ 讨论版][命题人: admin] 题目描述 Ta ...

  6. 6461:Tak and Cards(数位DP)

    6461: Tak and Cards 时间限制: 1 Sec   内存限制: 128 MB 提交: 173   解决: 63 [ 提交][ 状态][ 讨论版][命题人: admin] 题目描述 Ta ...

  7. Tak and Cards dp

    6461: Tak and Cards 时间限制: 1 Sec  内存限制: 128 MB 提交: 142  解决: 51 [提交][状态][讨论版][命题人:admin] 题目描述 Tak has ...

  8. ARC-060C - Tak and Cards - 动态规划

    题目描述 Tak has N cards. On the i-th (1≤i≤N) card is written an integer xi. He is selecting one or more ...

  9. [动态规划]Tak and Cards

    题目描述 Tak has N cards. On the i-th (1≤i≤N) card is written an integer xi. He is selecting one or more ...

最新文章

  1. CT片居然可以这么玩:用头部CT断层扫描片复原三维头像
  2. Docker安全加固——利用LXCFS增强docker容器隔离性和资源可见性
  3. ubuntu 下安装 VIM 依赖vim-common错误
  4. UA MATH523A 实分析3 积分理论例题 Fubini定理证明积分不等式
  5. C++引用不能绑定到临时数据
  6. 工作中非常逆天的shell命令
  7. WEB前端技术趋势图示-JS库
  8. 推荐一款.NET Core开源爬虫神器:DotnetSpider
  9. php passport security,php写的Passport加密函数
  10. SDRAM之持续中。。。。。。
  11. python bytes转int_Python学习进阶教程(11)—数值类型
  12. java 7 update 79下载_java 7下载|java运行环境(JDK 7 Update 67)官方版下载 - 3322软件站
  13. Python语言介绍
  14. JVM内存管理及垃圾回收机制
  15. 广东四大姓氏,排名第三的是李姓,你的姓氏排名第几?
  16. 【存储】存储基本概念(lun,volume,HBA,DAS,NAS,SAN,iSCSI,IPSAN、存储池和存储卷)
  17. 码畜 码奴 码农 IT民工和IT其他工种的划分定义
  18. 做了五套登录页,晒一下 自己比较满意的~ oh yeh~
  19. ajaxfileupload 上传插件
  20. CSR867x — Speaker Equalizer曲线调试笔记

热门文章

  1. 2020下半场:10本书教会你学习、思考和生活
  2. 马云:未来30年大数据时代,如何避免成为穷人?
  3. CANOpen服务数据对象报文
  4. android bitmap对比,Android Bitmap和Drawable的对比
  5. python如何安装pdfminer_|请教在python3中安装pdfminer.six的方法
  6. python的缩进规则具体是什么_python语句首字缩进规则
  7. 程序员管理思维修炼,只需要反复阅读本篇
  8. 乔新亮:以赢为终,三个月打造一支硬核IT团队
  9. 漫画:程序员真是太太太太太有趣了!
  10. JEECG 智能开发平台二次开发帮助文档