poj 1837 DP
来源:互联网 发布:大疆飞控算法 编辑:程序博客网 时间:2024/06/04 18:55
dp【i】【j】表示加入第i个物品之后和力矩为j的个数
由于数组下标不能为负数,所以全部加上7500(15*25*20)
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int dp[21][16000];int pos[21], weight[21];int C, G;int main(){ while( scanf( "%d%d", &C, &G ) != EOF ){ for( int i = 1; i <= C; i++ ){ cin >> pos[i]; } for( int i = 1; i <= G; i++ ){ cin >> weight[i]; } memset( dp, 0, sizeof( dp ) ); dp[0][7500] = 1; for( int i = 1; i <= G; i++ ){ for( int j = 1; j <= C; j++ ){ int temp = weight[i] * pos[j]; if( temp >= 0 ){ for( int k = temp; k <= 15000; k++ ){ dp[i][k] += dp[i-1][k-temp]; } }else{ for( int k = 15000 + temp; k >= 0; k-- ){ dp[i][k] += dp[i-1][k-temp]; } } } } cout << dp[G][7500] << endl; } return 0;}
0 0
- POJ 1837 Balance DP
- POJ 1837 dp
- POJ--1837--Balance--DP
- POJ 1837 Balance (DP)
- poj 1837 DP
- POJ 1837 Balance DP
- POJ 1837 Balance (DP)
- poj 1837 DP
- poj 1837 Balance (DP)
- POJ 1837 Balance DP
- POJ 1837 Balance (DP)
- POJ 1837 Balance (DP)
- poj 1837 dp
- poj 1837 Balance -DP
- POJ 1837 Balance(DP)
- poj 1837 dp
- POJ 1837 dp
- POJ-1837-Balance-DP
- 最后一个寒假结束
- android 绘制折线图(AChartEngine)Linechart 动态更新横轴为获取的当前时间
- 关键技术汇总
- SQLServer数据库约束(1)_表内约束(单表的五类约束)_附自增属性以及全局唯一性标识符类型作为主键
- substr(a.object_name, 1, length(b.object_name)) = b.object_name 优化
- poj 1837 DP
- test
- Protel中的元器件旋转
- Vim多文件搜索特定内容
- 回调函数
- RESTEasy使用httpclient上传文件
- mysql_free_result&bool mysqli_close
- ecshop模版设置添加广告不成功
- 最短路