codeforces Paying up 题解
来源:互联网 发布:在线真心话大冒险软件 编辑:程序博客网 时间:2024/05/18 16:58
找出一个数组中能否凑成一个给定的值。
就是相当于找零问题。使用动态规划法了。
原题:
http://www.codechef.com/problems/MARCHA1/
Example
Input:53 31115 111248165 231248165 13155101020 132176499825413725915315432819123542857236873599999Output:YesYesYesNoYes
#include <string>#include <algorithm>#include <stdio.h>#include <iostream>using namespace std;namespace{static const int ALL_MON = 1000;}int Payingup(){int T = 0, n, m; // n, the number of banknotes in your wallet, and m, the amount of money the muggers asked of you. scanf("%d", &T);while (T--){scanf("%d %d", &n, &m);int *A = new int[n];for (int i = 0; i < n; i++){scanf("%d", &A[i]);}if (m > ALL_MON){puts("No");continue;}int *B[2];B[0] = new int[2*m+2];memset(B[0], 0, (2*m+2)*sizeof(int));B[1] = B[0] + m+1;bool id = 0;B[0][0] = B[1][0] = 1;for (int i = 0; i < n; i++){id = !id;for (int j = 1; j <= m; j++){if (B[!id][j] || j >= A[i] && B[!id][j - A[i]]) B[id][j] = 1;}}if (B[id][m]) puts("Yes");else puts("No");delete [] A;delete [] B[0];}return 0;}
1 0
- codeforces Paying up 题解
- codechef Cleaning Up 题解
- 【codeforces】Ohana Cleans Up
- Ohana Cleans Up CodeForces
- 1711-Sum It Up 题解
- codeforces 141E clearing up
- CodeForces 554BOhana Cleans Up
- CodeForces 554BOhana Cleans Up
- codeforces Round #180题解
- Codeforces 241 div2题解
- codeforces Epic Game 题解
- Codeforces Amusing Joke 题解
- CodeForces Dubstep 题解
- codeforces A. Cakeminator 题解
- codeforces Towers 题解
- codeforces Gravity Flip 题解
- codeforces Flipping Game 题解
- codeforces A. TL 题解
- C++第9周(春)项目2 - Time类
- Android开发之Handler和Looper的关系
- 一篇文章让你读懂iOS和Android的历史起源
- nyoj 420 p次方求和
- hdu-1181-变形课
- codeforces Paying up 题解
- 用devstack安装Openstack,解决重启无法登陆问题
- hdu 2586 lca在线算法(朴素算法)
- 第九周项目二
- Ubuntu图形界面和console界面转换
- 《世界如此险恶,你要内心强大》读书笔记(一)
- Android中应用的资源
- sqlite3的一些问题
- [Python]heapq 堆模块