7.24每日总结《我能怎么办我也很绝望啊》

今天又被布置了三道题。
100342D 100342F 100342G
只做了100342D,高精度居然还能写错。。。然而还没调对。。。
这题就是高精度+简单dp
错误代码,仅作记录。。。

using namespace std;
const int maxn=410;
struct bign
{
    int siz,s[maxn],f;
    bign ()
    {memset(s, 0, sizeof(s));siz=1;}
    bign (int num)
    { *this = num; }
    bign (const char *num)
    { *this = num; }
    bign operator = (const char *num)
    {
        siz=int(strlen(num));
        for(int i=0;num[i]=='0';num++);
        for(int i=0;i<siz;i++)
        {
            s[i]=num[siz-i-1]-'0';
        }
        return *this;
    }
    bign operator = (const int num)
    {
        char s[maxn];
        sprintf(s,"%d",num);
        *this=s;
        return *this;
    }
    bool operator < (const bign &b)
    {
        if(siz!=b.siz)
            return siz<b.siz;
        for(int i=siz-1;i>=0;i--)
        {
            if(s[i]!=b.s[i])
                return s[i]<b.s[i];
        }
        return false;
    }
    bool operator > (const bign &b)
    {
        if(siz!=b.siz)
            return siz>b.siz;
        for(int i=siz-1;i>=0;i--)
        {
            if(s[i]!=b.s[i])
                return s[i]>b.s[i];
        }
        return false;
    }
    bool operator == (const bign num)
    {
        return !(*this>num) && !(*this<num);
    }
    bool operator != (const bign num)
    {
        return !(*this==num);
    }
    bign operator + (const bign &b)
    {
        bign c;
        c.siz=0;
        int j=0;
        for(int i=0;(j || i<max(siz,b.siz));i++)
        {
            int x=j;
            if(i<siz)
                x+=s[i];
            if(i<b.siz)
                x+=b.s[i];
            c.s[c.siz++]=x%10;
            j=x/10;
        }
        return c;
    }
    bign operator * (const bign &b)
    {
        bign c;
        c.siz=siz+b.siz;
        for(int i=0;i<siz;i++)
        {
            for(int j=0;j<b.siz;j++)
            {
                c.s[i+j]+=s[i]*b.s[j];
            }
        }
        for(int i=0;i<c.siz;i++)
        {
            c.s[i+1]+=c.s[i]/10;
            c.s[i]%=10;
        }
        return c;
    }
    void begi()
    {
        f=-1;
    }
    void str()
    {
        for(int i=0;i<siz;i++)
            cout<<s[i];
        cout<<endl;
    }
};
bign dp[105][105];
int n,k;
bign dfs(int i,int j)
{
    if(dp[i][j]!=-1)
        return dp[i][j];
    else
    if(i>j)
    {
        dp[i][j]=0;
        return 0;
    }
    else
    {
        if(i==0 && j==0)
        {
            dp[i][j]=1;
            return 1;
        }
        else
        {
            if(i==0)
            {
                dp[i][j]=dfs(i,j-1)*k;
                return dp[i][j];
            }
            else
            {
                dp[i][j]=dfs(i-1,j-1)*i+dfs(i,j-1)*(k-i);
                return dp[i][j];
            }
        }
    }
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<=100;i++)
        for(int j=0;j<=100;j++)
            dp[i][j]=-1;
    dp[0][0]=1;
    bign ans=dfs(k,n);
    ans.str();
    return 0;
}

然后是昨天atcoder grand contest018的b,a的话已经对了,然而b还没有改对,这题是个“感性”的贪心,就是要做到每一步操作都是最优的。依旧是错误代码。。。

using namespace std;
int n,m,tot;
int a[305][305];
int ma[305];
bool f=1;
bool used[305];
vector<pair<int,bool> > tr;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    int sum=0,spo=0;
    for(int i=1;i<=n;i++)
    {
        ma[a[i][1]]++;
    }
    for(int i=1;i<=m;i++)
    {
        if(ma[i]>0)
            tr.pb(mp(i,0));
        if(sum<ma[i])
        {
            sum=ma[i];
            spo=i;
        }
    }
    int i=spo;
    //cout<<"-------"<<endl;
    //cout<<spo<<":"<<sum<<endl;
    //cout<<"-------"<<endl;
    while(f)
        for(int p=0;p<tr.size();p++)
        {
            memset(ma,0,sizeof(ma));
            tr[p].se=1;
            tot++;
            used[i]=1;
            for(int k=1;k<=n;k++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(!used[a[k][j]])
                    {
                        ma[a[k][j]]++;
                        break;
                    }
                }
            }
            used[i]=0;
            int sum1=0,spo1=0;
            //cout<<"-------"<<endl;
            vector<pair<int,bool> > tr1;
            for(int j=1;j<=m;j++)
            {
                if(ma[j]>0)
                    tr1.pb(mp(j,0));
                if(sum1<ma[j])
                {
                    sum1=ma[j];
                    spo1=j;
                }
                //cout<<ma[j]<<" ";
            }
            //cout<<endl;
            //cout<<"-------"<<endl;
            //cout<<spo1<<":"<<sum1<<endl;
            if(sum1<=sum && !used[spo1])
            {
                used[spo]=1;
                sum=sum1;
                spo=spo1;
                i=spo;
                tr=tr1;
                //cout<<"-------"<<endl;
                //cout<<spo<<":"<<sum<<endl;
            }
            else
            {
                if(tot<tr.size())
                    i=tr[tot+1].fi;
            }
            if(tot==tr.size())
            {
                f=false;
            }
        }
    cout<<sum<<endl;
    return 0;
}

还有一道是85d,这题一直超时,打算看一下题解再写,就不贴代码了。。。

转载于:https://www.cnblogs.com/NightRaven/p/9333249.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值