| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
。。#include<iostream>
#include<cstring>
using namespace std;
int fac[10];
int target[1040];
bool b[1000001];
int main()
{
fac[0] = 1;
for(int i = 1; i < 10; i++)
fac[i] = fac[i-1] * i;
//用for清零好像慢了100ms,参考下
memset(b, 0, sizeof(b));
for(int i = 1; i < 1024; i++)
{
target[i] = 0;
//10个数的组合可能性有2<<10种
//用数字i的二进制的每一位表示的组合的取舍,用(i & (1 << j))测验,就能整理全部可能性
for(int j = 0; j < 10; j++)
if(i & (1<<j))
target[i] += fac[j];
b[target[i]] = true;
}
// for(int i = 0; i < 10; i++)
// cout << target[i] << endl;
int n;
while(cin >> n && n >= 0){
if(b[n] == true)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator