UVa 357 - Let Me Count The Ways
2013-04-09 10:55
471 查看
还是硬币的问题,开始毫不犹豫的按之前的思路。写完,提交,WA。很尴尬。也用了long long。不知道什么原因30000这个就是表示不出来。找到了WA的原因,真是一头雾水啊。后来看了discuss发现有用一维数组的。于是想起了看过滚动数组可以优化。于是抱着尝试的态度。用了滚动数组优化。结果TLE,TLE的原因就是没有加 != EOF 时间居然是是3.000 和 0.016 居然差这么多。真的很诧异。。。
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; int Case; long long dp[30010], ans; int V[5] = { 1, 5, 10, 25, 50 }; void solve ( ) { memset ( dp, 0, sizeof ( dp ) ); dp[0] = 1; for ( int i = 0; i < 5; ++i ) for ( int j = 1; j < 30010; ++j ) if ( j >= V[i] ) dp[j] += dp[j - V[i]]; } int main ( ) { solve ( ); while ( scanf ( "%d", &Case ) != EOF ) { if ( dp[Case] > 1 ) printf ( "There are %lld ways to produce %d cents change.\n", dp[Case], Case ); else printf ( "There is only 1 way to produce %d cents change.\n", Case );; } return 0; }
相关文章推荐
- uva_357 Let Me Count The Ways
- 【解题报告】uva357_Let Me Count The Ways(让我来数数方案, dp, 完全背包)
- UVA 357 - Let Me Count The Ways
- UVa 357 - Let Me Count The Ways 背包
- uva 357 Let Me Count The Ways(01背包)
- UVA - 357 Let Me Count The Ways
- UVa 357 Let Me Count The Ways (完全背包)
- UVA 357 - Let Me Count The Ways(母函数)
- UVa 357 - Let Me Count The Ways
- UVA 357 Let Me Count The Ways(全然背包)
- UVa 357 - Let Me Count The Ways 背包
- UVA - 357 Let Me Count The Ways
- UVA - 357 Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- uva 357 - Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- UVA 357 Let Me Count The Ways 动态规划解法、母函数解法
- UVA 357 - Let Me Count The Ways
- UVA 357 Let me count the ways