楼教的男人八题名气甚大,今天做了一道感觉还是涨了不少姿势的,然而估计之后的每道题都要看题解吧,姑且先记录一下。以后再做再更
1737 | Connected Graph | 1100 | LouTiancheng@POJ |
1738 | An old Stone Game | 407 | LouTiancheng@POJ |
1739 | Tony's Tour | 671 | LouTiancheng@POJ |
1740 | A New Stone Game | 2240 | LouTiancheng@POJ |
1741 | Tree | 1728 | LouTiancheng@POJ |
1742 | Coins | 4309 | LouTiancheng@POJ |
1743 | Musical Theme | 2687 | LouTiancheng@POJ |
1744 | Elevator Stopping Plan | 469 | LouTiancheng@POJ |
所谓男人八题就是以上八道了,我做的是最简单的一道,1742,dp,这题不把数组写成一维会mle,代码记录如下:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxv=1e5+30; int n,m; int dp[maxv]; int a[104],c[105]; int main(){ //freopen("in","r",stdin); while(cin>>n>>m){ if(n==0&&m==0) break; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&c[i]); memset(dp,-1,sizeof dp); dp[0]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=m;j++){ if(dp[j]>=0) dp[j]=c[i]; else if(j-a[i]<0||dp[j-a[i]]<0) dp[j]=-1; else dp[j]=dp[j-a[i]]-1; } } int ans=0; for(int i=1;i<=m;i++){ if(dp[i]>=0) ans++; } cout<<ans<<endl; } return 0; }