标签:ref 个数 class 整数 ams space int pre problem
5 5 1 2 3 4 5
3
关键字:01背包,逆序
1 //************************************* 2 //7-1 PAx: 620终端 3 // Name: 2728:摘花生 4 // Solut: D.P. 5 //************************************ 6 #include "stdafx.h" 7 #include<bits/stdc++.h> 8 #define N 21 9 using namespace std; 10 int n, k; 11 int a[N],f[N*N*N]; 12 int main() 13 { 14 scanf("%d%d", &n,&k); 15 for (int i = 1; i <= n; i++) 16 { 17 scanf("%d", &a[i]); 18 } 19 f[0] = 1; 20 for (int i = 1; i <= n; i++) 21 { 22 for (int j = k; j >= a[i]; j--) 23 { 24 f[j] += f[j - a[i]]; 25 } 26 } 27 printf("%d\n", f[k]); 28 return 0; 29 }
标签:ref 个数 class 整数 ams space int pre problem
原文地址:http://www.cnblogs.com/InfoEoR/p/7105514.html