简单的题意如下:
小明最近做出了一道题:如何在一组数中寻找三个数,这三个数的和等于一给出的定值m,洋洋得意。于是小华不乐意了,别问为什么…,于是小华说,你能找找在一组数字中是否有n个数,使得这n个数的和等于一给定的定值m吗?
1): 0 < n <= 10000
2): 0 < 序列长度 <= 10000
3): 0 <= m <=10000
4): 0 <= 数组中的数 <=10000
还有比这更简单易懂的题目吗???
呵呵达,想了好久n^2的dp过不去,后来发现可以bitset优化,还有这题读入也是醉了。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
int v[10005];
int x, f, cnt;
bitset <10005> _x;
int Scan()
{
int res = 0;
char c;
cnt = 0;
while(~(c = getchar()))
{
if(c == ' ')
{
v[cnt++] = res;
res = 0;
}
else if(c == '\n')
{
if(f == 0)v[cnt++] = res;
else x = res;
f++;
res = 0;
}
else res = res * 10 + c - '0';
if(f == 2)
{
_x.reset();
_x[0] = 1;
for(int i = 0; i < cnt; ++i)_x |= _x << v[i];
if(_x[x])puts("Yes");
else puts("No");
cnt = f = res = 0;
}
}
_x.reset();
_x[0] = 1;
for(int i = 0; i < cnt; ++i)_x |= _x << v[i];
if(_x[res])puts("Yes");
else puts("No");
}
int main()
{
//freopen("in.txt", "r", stdin);
f = 0;
Scan();
return 0;
}