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

贴个0MS代码

Posted by speedcell4 at 2011-10-12 22:09:04 on Problem 1837
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <string>
#include <bitset>
#include <complex>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <locale.h>

#define loop(i,a,b) for(int i=a;i<=b;i++)
#define clr(a,val) memset(a,val,sizeof(a))

using namespace std;

const int MAXN = 21;
const int MAXV = 15000;

typedef long long ll;
ll n,m,a[MAXN],b[MAXN],dp[MAXN][MAXV];

inline bool ReadIn(void)
{
    if(scanf("%I64d %I64d",&n,&m)==EOF) return false;
    else
    {
        clr(dp,0); dp[0][MAXV/2]=1;
        loop(i,1,n) scanf("%I64d",&a[i]);
        loop(i,1,m) scanf("%I64d",&b[i]);
        return true;
    }
}

int main()
{
    while(ReadIn())
    {
        loop(i,1,m) loop(j,1,MAXV)
        {
            if(dp[i-1][j])
            {
                loop(k,1,n) dp[i][j+a[k]*b[i]]+=dp[i-1][j];
            }
        }
        printf("%I64d\n",dp[m][MAXV/2]);
    }
    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