Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

G++过不了,,C++神奇过了。。

Posted by 2010030402005 at 2011-08-02 23:39:06 on Problem 1775
#include <iostream>
#include <cstdio>
using namespace std;
int s[10]={1,1,2,6,24,120,720,5040,40320,362880};
int sum;
int n;
int temp;
int dfs(int a)
{
  for(int j=a;j<=9;j++)
    {
      sum=sum+s[j];
      if(sum==n)
	{
	  temp=1;
	return 1;
	}
      dfs(j+1);
	if(temp==1)
	  return 1;
       sum=sum-s[j];
    }
}
int main()
{
  int tem;
  while( cin>>n && n>-1){
    sum=0;
    temp=0;
    if(n == 0)
      {
	printf("NO\n");
	continue;
      }
    tem=dfs(0);
    if(tem==1)
      printf("YES\n");
    else printf("NO\n");
  }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator