高橋君とカード / Tak and Cards
高橋君とカード / 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≤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.
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的更多相关文章
- 高橋君とカード / 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 ...
- AtCoder Beginner Contest 044 C - 高橋君とカード / Tak and Cards
题目链接:http://abc044.contest.atcoder.jp/tasks/arc060_a Time limit : 2sec / Memory limit : 256MB Score ...
- 高橋君とホテル / Tak and Hotels
高橋君とホテル / Tak and Hotels Time limit : 3sec / Stack limit : 256MB / Memory limit : 256MB Score : 700 ...
- 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 ...
- AT987 高橋君
AT987 高橋君 给出 \(n,\ k\) ,求 \(\displaystyle\sum_{i=0}^kC_n^k\) , \(T\) 次询问 \(T\leq10^5,\ 0\leq k\leq n ...
- 【AT987】高橋君
题目 成爷爷一眼秒,\(tql!!!\) 多组询问,求 \[\sum_{i=0}^kC_{n}^i \] 发现\(k<=n\)啊,于是我们可以把一组询问抽象成一个区间\([k,n]\) 左指针的 ...
- AtCoder D - 高橋君と見えざる手 / An Invisible Hand 简单思维题
http://arc063.contest.atcoder.jp/tasks/arc063_b 因为每次都是选取最大值,那么用dp[i]表示第i个数结尾能得到最大是多少. 其实就是用a[i]去减去左边 ...
- 2018.09.17 atcoder Tak and Cards(背包)
传送门 背包经典题. 直接f[i][j]f[i][j]f[i][j]表示选i张牌和为j的方案数. 最后统计答案就行了. 代码: #include<bits/stdc++.h> #defin ...
- AtCoder-arc060 (题解)
A - 高橋君とカード / Tak and Cards (DP) 题目链接 题目大意: 有 \(n\) 个数字,要求取出一些数字,使得它们的平均数恰好为 \(x\) ,问有几种取法. 大致思路: 只要 ...
随机推荐
- java web服务器tomcat介绍【转载】
机器矩阵2016-08-10 22:14 java程序员亲切地称他为tom猫,看到这只猫可以说明1 服务器部署成功了 ,2 网络是联通的. 到底这只猫是什么来头呢? tomcat是Apache基金会下 ...
- MyEclipse运行到断点也跳过的问题
如果是B/S开发也就是javaWeb开发的话,Tomcat 的启动模式要设置成Debug模式 还有下面是没运行时断点的样子: 运行的时候,断点会变成对钩,表示执行到它所在代码的时候会停下来:
- js获取后台json数据显示在jsp页面元素
jsp id <font size=2 >Today:</font> <font id ="todaytotal" size=2 color=&quo ...
- LVS负载均衡中arp_ignore和arp_annonuce参数配置的含义
先简单的介绍下关于LVS负载均衡 LVS(Linux Virtual Server)Linux服务器集群系统 针对高可伸缩,高可用服务的需求,给予IP层和内容请求分发的负载均衡调度解决方法,并在Li ...
- IIS express 7.5 设置默认文档
在C:\Users\[电脑用户名]\Documents\IISExpress\config 下面有个applicationhost.config文件,打开文件找到<system.webServe ...
- linux 文件系统操作()
1. 用Xshell 客户端连上远程主机. 2.ll 或 ls 查看当前目录下的文件或目录, cd / 切换到根目录, cd **切换到某个目录(或者叫进入某个文件夹) 3.文件的压缩命令:zip - ...
- auto_ptr浅析
auto_ptr是C++标准库中(<utility>)为了解决资源泄漏的问题提供的一个智能指针类模板(注意:这只是一种简单的智能指针) auto_ptr的实现原理其实就是RAII,在构造的 ...
- POJ 2975 Nim 尼姆博弈
题目大意:尼姆博弈,求先手必胜的情况数 题目思路:判断 ans=(a[1]^a[2]--^a[n]),求ans^a[i] < a[i]的个数. #include<iostream> ...
- 初识Selenium(一)
Selenium入门相关PPT参考网址:http://wenku.baidu.com/view/d1e7d90390c69ec3d5bb7565.html?from=search 内容引用网址:htt ...
- 使用runloop阻塞线程的正确写法
使用runloop阻塞线程的正确写法 runloop可以阻塞线程,等待其他线程执行后再执行. 比如: @implementation ViewController{ BOOL end;}…– ( ...