博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Beginner Contest 044 C - 高橋君とカード / Tak and Cards
阅读量:4364 次
发布时间:2019-06-07

本文共 1904 字,大约阅读时间需要 6 分钟。

C - 高橋君とカード / Tak and Cards


Time limit : 2sec / 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 Ax1 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

Copy
4 87 9 8 9

Sample Output 1

Copy
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

Copy
3 86 6 9

Sample Output 2

Copy
0

Sample Input 3

Copy
8 53 6 2 8 7 6 5 9

Sample Output 3

Copy
19

Sample Input 4

Copy
33 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

Sample Output 4

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

 

题意:给定一串数字,问能够组成多少种不连续子串使得子串的平均数为某个数

题解:用动态规划,i表示相加的个数,j表示加起来后的值

#include
using namespace std;const int N=55;long long dp[N][N*N]; //dp值会爆intint main(){ int n,a; cin>>n>>a; dp[0][0]=1; for(int i=1;i<=n;i++) { int x; cin>>x; for(int j=i-1;j>=0;j--) //每一次个数向下减少 for(int k=0;k<=N*j;k++) //优化时间 由于k最大为N*j次 dp[j+1][k+x]+=dp[j][k]; //个数加1 则找到前面个数的值相加 } long long ans=0; for(int i=1;i<=n;i++) ans+=dp[i][i*a]; //累计所有个数会出现平均值满足a的情况 cout<
<

 

转载于:https://www.cnblogs.com/Scalpel-cold/p/7259118.html

你可能感兴趣的文章
文件操作
查看>>
7.java集合,泛型简单总结,IO流
查看>>
杭电2007 平方和与立方和
查看>>
JS邮箱验证-正则验证
查看>>
Quartz 2D绘图
查看>>
JS Fetch
查看>>
EJB 笔记
查看>>
【delete】Android自定义控件(四) 自定义ImageView动态设置ImageView的高度
查看>>
HDUOJ------(1230)火星A+B
查看>>
Servlet
查看>>
基于jquery地图特效全国网点查看代码
查看>>
【leetcode】867 - Transpose Matrix
查看>>
selenium动作链
查看>>
敏捷外包工程系列之二:人员结构(敏捷外包工程,敏捷开发,产品负责人,客户价值)...
查看>>
《设计你的人生》的部分经典语录
查看>>
mustache多次渲染和多个赋值
查看>>
Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十三】
查看>>
linux-nohup命令
查看>>
[LeetCode OJ] Roman to Integer
查看>>
三次握手和四次挥手
查看>>