| ||||||||||
| 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 | |||||||||
DP水题。附代码#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define MX 20000000000000005
#define Mx 200000005
using namespace std;
int dp[25][5005],i,j,n,m;
int a[25],b[25];
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin>>n>>m;
int i,j,k;
for(i=1;i<=n;i++) cin>>a[i];
for(i=1;i<=m;i++) cin>>b[i];
dp[0][2500]=1;
for(i=1;i<=m;i++){
for(k=0;k<5000;k++){
if(dp[i-1][k]){
for(j=1;j<=n;j++){
// if(k+b[i]*a[j]>-1&&k+b[i]*a[j]<5000){
dp[i][k+b[i]*a[j]]+=dp[i-1][k];
// }
}
}
}
}
cout<<dp[m][2500]<<endl;
return 0;
#ifdef home
eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator