HDU 1789 Doing Homework again
2016-05-02 16:10
567 查看
简单贪心。
按分值排序,一个一个取,不能取的对答案就作出了贡献。
按分值排序,一个一个取,不能取的对答案就作出了贡献。
#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<map> #include<algorithm> using namespace std; const int maxn=5000; int n; bool flag[maxn]; struct X { int z; int c; }s[maxn]; bool cmp(const X&a,const X&b) { return a.c>b.c; } int main() { int T; scanf("%d",&T); while(T--) { memset(flag,0,sizeof flag); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&s[i].z); for(int i=1;i<=n;i++) scanf("%d",&s[i].c); sort(s+1,s+1+n,cmp); int ans=0; for(int i=1;i<=n;i++) { bool f=0; for(int j=s[i].z;j>=1;j--) { if(flag[j]==0) { f=1; flag[j]=1; break; } } if(f==0) ans=ans+s[i].c; } printf("%d\n",ans); } return 0; }
相关文章推荐
- what's the cygwin and how cai i install this software
- 70. Climbing Stairs
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- 70. Climbing Stairs
- container_of 宏、offsetof 宏 分析
- Flex AIR ANT 脚本编译
- CodeForces 667A Pouring Rain
- CodeForces 667A Pouring Rain
- hdu2925 Musical Chairs && poj3517 And Then There Was One(约瑟夫环)
- Raid 级别
- Hibernate运行报错Unknown entity: domain.UserBean
- HDU 3394 Railway 点双连通分量 + 桥
- Rails,ACM/ICPC CERC 1997,UVa514
- Insufficient memory<failed to allocate 232852> in cv::OutOfMemoryError
- LeetCode 217. Contains Duplicate
- codeforces 667A A. Pouring Rain(水题)
- poj2010 Moo University - Financial Aid(最大化第k大)
- leetcode 070 climbing stairs
- Coremail手机版页面持久型XSS实践
- kali无线渗透之Aireplay-ng小谈