AtCoder Beginner Contest 044 C - 高橋君とカード / Tak and Cards
题目链接: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≤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.
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
题意:给定一串数字,问能够组成多少种不连续子串使得子串的平均数为某个数
题解:用动态规划,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的更多相关文章
- 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 ...
- 高橋君とカード / Tak and Cards
高橋君とカード / Tak and Cards Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB Score : 300 p ...
- 高橋君とカード / 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 ...
- 高橋君とホテル / Tak and Hotels
高橋君とホテル / Tak and Hotels Time limit : 3sec / Stack limit : 256MB / Memory limit : 256MB Score : 700 ...
- AtCoder Beginner Contest 044 B - 美しい文字列 / Beautiful Strings
Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Let w be a string cons ...
- AtCoder Beginner Contest 022 A.Best Body 水题
Best Body Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://abc022.contest.atcoder.jp/tasks/abc02 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
- AT987 高橋君
AT987 高橋君 给出 \(n,\ k\) ,求 \(\displaystyle\sum_{i=0}^kC_n^k\) , \(T\) 次询问 \(T\leq10^5,\ 0\leq k\leq n ...
随机推荐
- pymongo模块 目录
MongoDB pymongo模块 MongoDB pymongo模块 查询 MongoDB pymongo模块 插入数据 MongoDB pymongo模块 更新数据 MongoDB pymongo ...
- weixin.com的whois信息变更为腾讯了 是准备替换weixin.qq.com吗?
微信双拼域名weixin.com的whois信息变更,所有人为腾讯.从weixin.com在10月18日这次的whois变更上,透露出腾讯似乎准备启用这个域名.如果启用,毋庸置疑是要应用在腾讯的巨无霸 ...
- 安装与破解PyCharm专业版
安装与破解PyCharm专业版(有两种方法) 一.安装与破解PyCharm专业版 1.安装pycharm(建议安装python3) 这是网址:(https://www.jetbrains.com/py ...
- typedef 详解
一行很常用的代码: typedef int XX_Size_Check[(sizeof(XX)==64)? 1:-1]; 很容易猜到上面这行代码是要在编译时检查XX的size,但再深究点,我们就会发现 ...
- 浪潮IOT知识点
1 新增身份定义 以及 身份定义的属性表 要注意增加路由 2 '@trident/core'; 飘红,解决办法 import { TableSearchComponent } from '@t ...
- 实习培训——Java多线程(9)
实习培训——Java多线程(9) 很适合新手 http://www.cnblogs.com/GarfieldEr007/p/5746362.html http://www.cnblogs.com/Ga ...
- 查看Nginx、PHP、Apache和MySQL的编译参数
1.查看Nginx编译参数 [root@portal finance]# your_nginx_dir/sbin/nginx -V nginx version: nginx/ built by (Re ...
- sublime使用经验汇总
1. source insight 会对某个修改频繁的文件做多次备份.我们用sublime进行多个文件搜索时,需要把备份的文件排除在外. e:\work\code\sourcev, *.h, *.cp ...
- NserviceBus:消息Message、Command、Event(2)
NServiceBus.IMessage 用于定义消息.NServiceBus.ICommand 用于定义命令.NServiceBus.IEvent 用于定义事件. ICommand 命令 用于点对点 ...
- iOS 开发笔记-控制器翻页
找了一天,终于找到了两个能用的. 1.https://github.com/wangmchn/WMPageController 2.https://github.com/everettjf/EVTTa ...